Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: The Accessor Heresy

by perrin (Chancellor)
on Nov 28, 2005 at 17:30 UTC ( [id://512293]=note: print w/replies, xml ) Need Help??


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.

Replies are listed 'Best First'.
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://512293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-20 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found