Originally Posted by
matsp
But if you are keeping LOTS of circles, storing all the area, diameter and circumference is a bit excessive, as they can all be calculated quite easily when needed. All you have to STORE in the function is the radius.
Using getter/setter functions will allow you to CONTROL what values are set, and to hide the internal representation.
For example, if we produce a class like you have above, and then decide that we can actually find the right circle much faster by simply storing the radius [because it takes up 1/4 of the space, and using less memory means we can walk through more of them in the same amount of time, approximately 4 times faster in fact], and calculating the other components, then we have to change ALL the code that uses area, circumference and diameter. If on the other hand, you have a function getArea() that returns the area, we can implement the area calculation either as part of the setRadius() or as part of the getArea() function - more freedom, less dependancy on the class data structure itself.
And of course, if fArea is private, you can't use = to set it anyways.
--
Mats