in reply to Class attribute get/set approach flaws?
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Class attribute get/set approach flaws?
by sauoq (Abbot) on Nov 29, 2005 at 01:37 UTC |