Since Perl's implementation of OO is commonly used with a hash, one hash for a class and all it's 'parents'. To avoid collision between names of inherited attributes a namespace is defined for each package and prepended to the attributes of an object. This is a poor summary of section 6.2.6 of OO Perl by Damian Donway.
Well it set me to thinking, that since I was brought up believing all properties of an object should be viewed through accessor methods, and altered through mutator methods, one way of achieving this was to slap on a long namespace to stop people tampering, it seemed a little more dictatorial than the '_' affordance, although I stuck to that too.
$object->{_id}; $object->{_private_property_of_template_called_id_leave_it_be}; # Both could then have an accessor method, respectively sub get_id () { $_[0]->{_id} } sub get_id () { $_[0]->{ _private_property_of_template_called_id_leave +_it_be } } # And each would be called $object->get_id();
Obviously, I hope, you can see that I've exagerated the length of the property, but does this makes sense to use? I really am in two minds as to whether this is a good thing, so I thought I'd post it here as people have some pretty strong views on OO...
--
Brother Frankus.
¤
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A new take on affordance.
by Biker (Priest) on May 16, 2002 at 14:17 UTC | |
Re: A new take on affordance.
by broquaint (Abbot) on May 16, 2002 at 13:25 UTC | |
Re: A new take on affordance.
by Caillte (Friar) on May 16, 2002 at 15:35 UTC | |
Re: A new take on affordance.
by Dog and Pony (Priest) on May 17, 2002 at 08:31 UTC | |
by dsheroh (Monsignor) on May 18, 2002 at 14:27 UTC | |
by Dog and Pony (Priest) on May 18, 2002 at 14:38 UTC | |
Re: A new take on affordance.
by P0w3rK!d (Pilgrim) on May 17, 2002 at 15:02 UTC | |
Re: A new take on affordance.
by Aristotle (Chancellor) on May 18, 2002 at 05:02 UTC |