Home Segments Top Top Previous Next

235: Mainline

Suppose, for example, that your program contains statements that read the minutes or hours of a particular attraction, x. If you work with getters, you need to make no change to that statement to accommodate the switch from a minutes-based class definition to an hours-based class definition:

... x.getMinutes() ... --> ... x.getMinutes() ... 
... x.getHours() ...   --> ... x.getHours() ... 

On the other hand, if you do not work with the instance variables in attractions that use constructors, getters, and setters only, then you have to go through your entire program, modifying myriad statements:

... x.minutes ...          --> ... (int)(x.hours * 60) ... 
... (x.minutes / 60.0) ... --> ... x.hours ... 

Thus, constructors, getters, and setters isolate you from the effects of your efficiency-motivated switch from a minutes-based class definition to an hours-based class definition.