Web proxy server - Chapter 8 Object-Based Programming 419 54 } //

Chapter 8 Object-Based Programming 419 54 } // end class PackageData Fig. 8.16 Package access to members of a class (part 2 of 2). Software Engineering Observation 8.19 Some people in the OOP community feel that package access corrupts information hiding and weakens the value of the object-oriented design approach, because the programmer must assume responsibility for error checking and data validation in any code that manipulates the package access data members. 8.13 Using the this Reference When a method of a class references another member of that class for a specific object of that class, how does Java ensure that the proper object is referenced? The answer is that each object has access to a reference to itself called the this reference. The this reference is used implicitly to refer to both the instance variables and methods of an object. We begin with a simple example of using the thisreference explicitly; a subsequent example shows some substantial and subtle examples of using this. Performance Tip 8.4 Java conserves storage by maintaining only one copy of each method per class; this method is invoked by every object of that class. Each object, on the other hand, has its own copy of the class s instance variables. The application of Fig. 8.17 demonstrates implicit and explicit use of the thisreference to enable the main method of class ThisTest to display the private data of a SimpleTimeobject. 1 // Fig. 8.17: ThisTest.java 2 // Using the this reference to refer to 3 // instance variables and methods. 4 5 // Java core packages 6 import java.text.DecimalFormat; 7 8 // Java extension packages 9 import javax.swing.*; 10 Fig. 8.17 Using the thisreference implicitly and explicitly (part 1 of 3). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01

Leave a Reply