in reply to The Accessor Heresy
This may be an academic example, but it's very weird to see you set the area of a circle. Personally I'd have a constructor that takes two arguments or three arguments: either a point or two coordinates (this is open for debate) and the radius of the circle. I'd have a getter for the point and the radius, as well as getters for the area (which would be computed from the radius) and such other properties. Point may be an object if necessary, but it could also be coded as an x- and y-coordinate.
I'd (if necessary) have methods such as move to change the coordinates of the midpoint and scale to change the radius.
This seems to me the way to manipulate a circle without fussing with its implementation and that is after all one of the goals of OO.
Just my 2 cents, -gjb-
Update: Apparantly I should clarify a bit. The points I'm trying to make with my casual description of a Circle class are (at least ;) the following:
- Getters/setters don't necessarily come in pairs and
- you can manipulate an object other than by setting some of its properties directly
As a last point: I don't care whether Radius is ann object or not since I'm not going to manipulate it directly in my example anyway.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: The Accessor Heresy
by sauoq (Abbot) on Nov 28, 2005 at 17:07 UTC | |
by gjb (Vicar) on Nov 28, 2005 at 17:12 UTC | |
by sauoq (Abbot) on Nov 28, 2005 at 17:40 UTC | |
by Roy Johnson (Monsignor) on Nov 28, 2005 at 18:36 UTC | |
by gjb (Vicar) on Nov 28, 2005 at 19:03 UTC |