Yes. The set
methods can change the dimensions of the Cone
but the instance variables for area
and volume
retain their old values.
This results in an inconsistent state for the object.
Of course, you could re-calculate area
and volume
in each set method (if you remember), but this results in redundant code.
Or you could keep the previous versions of the area()
and volume()
, but now there is little reason to have those values
as instance variables.
A design rule is to avoid redundant calculations and avoid storing values that can easily be calculated from essential values. This is true for database design as well as for programming.
You have reached the end of the chapter. There is much more to learn about defining classes. The next chapter continues the discussion.
Cone
class.
Cone
class.