use Objet; my $o = Objet->new('aleph' => 1, 'gamma' => 2); $o->attrib( 'zeta' => 900 ); # sets attribute 'zeta' to 900 print $o->attrib( 'aleph' ); # gets value of attrib 'aleph'
One thing "wrong" with this approach is that you now have symbolic references, in effect. What if you misspell the name of the attribute? You have to some way to validate the attribute names at run-time (or, at least, you ought to).
Using separate subs to be the setters and getters will give you a run-time exception if you misspell the attribute name. This can be seen as a better thing than quietly Doing The Wrong Thing.
In reply to Re: Class attribute get/set approach flaws?
by herveus
in thread Class attribute get/set approach flaws?
by radiantmatrix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |