in reply to The Accessor Heresy
That's the wrong direction. Having "Area" be a contained object only makes it more obvious to the caller that this is setting a variable. The caller is not supposed to care about that. A method called "set_area" should be able to set a simple property, or set several properties and call some calculation methods, or make a SOAP call, or whatever. That sort of abstraction is the main reason to use OO.
Re^2: The Accessor Heresy
by Roy Johnson (Monsignor) on Nov 28, 2005 at 17:56 UTC
|
You're suggesting that there are no such things as conceptual properties. You are wrong. Calling set_area should conceptually set the area of whatever object it is. And that "area" that is being set is a thing, which (in OO programming) means you implement it as an object.
Furthermore, the Area->set method of a sub-object can do absolutely anything the set_area property can do. It is every bit as abstract, it just corresponds better to the suggested model. Notice that in my example, both Area and Radius operate on the radius value. They do not have their own independent set of data; the radius value is owned by the Circle object.
Caution: Contents may have been coded under pressure.
| [reply] [d/l] [select] |
|