Chapter 8 Object-Based (Best web hosting site) Programming 297 Fig. 8.5 Fig.
Chapter 8 Object-Based Programming 297 Fig. 8.5 Fig. 8.Fig.Fi 8.5g. 8.55Overloaded constructor demonstration. (Part 3 of 3.) Fig. 8. Each Time2constructor can be written to include a copy of the appropriate statements from method SetTime. This might be slightly more efficient, because it eliminates the extra call to SetTime. However, consider what would happen if the programmer were to change the representation of the time from three int values (requiring 12 bytes of memory) to a single intvalue representing the total number of seconds that have elapsed in the day (requiring 4 bytes of memory). Placing identical code in the Time2constructors and method SetTimemakes such a change in the class definition more difficult, because every constructor s body would require modifications to manipulate the data as a single int rather than three ints. If the Time2 constructors call SetTime directly, any changes to the implementation of SetTimemust be made only once, in the body of Set- Time. This reduces the likelihood of introducing a programming error when altering the implementation, because we make only one change in the class, rather than changing every constructor and method SetTime. Software Engineering Observation 8.14 If a method of a class provides functionality required by a constructor (or other method) of the class, call that method from the constructor (or other method). This simplifies the maintenance of the code and reduces the likelihood of introducing errors into the code. 8.7 Properties Methods of a class can manipulate that class s privateinstance variables. A typical manipulation might be the adjustment of a customer s bank balance a private instance variable of a class BankAccount by a ComputeInterestmethod. Classes often provide publicproperties to allow clients to set (i.e., assign values to) or get (i.e., obtain the values of) privateinstance variables. For example, in Fig. 8.6, we create three properties Hour, Minute and Second which access variables hour, minute and second, respectively. Each property contains a get accessor (to retrieve the field value) and a set accessor (to modify the field value).
Check Tomcat Web Hosting services for best quality webspace to host your web application.