No such thing as a small change | |
PerlMonks |
Re: Object accessors with unknown data (hash)by tye (Sage) |
on Jan 26, 2015 at 14:25 UTC ( [id://1114527]=note: print w/replies, xml ) | Need Help?? |
Doesn't sound like you have anything that qualifies as a class. Sounds like you have a hash. Accessor methods named after attributes are anti-modular. Using such for ad-hoc attributes provide zero benefit (to go along with the significant drawbacks). Now, if you have special behavior that you want to implement, then it can make sense to write a class. But the ad-hoc key/value pairs are not the attributes of the objects. The attributes of the object are whatever pieces of data you need in order to implement the interface. In the simplest case, you build a class with a single attribute, a hash (ref). Then the methods you build tend to provide the basic functions that Perl hashes provide:
Those methods can do extra things that just a hash wouldn't do (prevent write access, detect use of non-present keys). More likely, you have other behaviors that lead to the need for at least one or two other attributes (which you probably shouldn't build accessors for). - tye
In Section
Seekers of Perl Wisdom
|
|