in reply to Class attribute get/set approach flaws?

Howdy!

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.

yours,
Michael

Replies are listed 'Best First'.
Re^2: Class attribute get/set approach flaws?
by sauoq (Abbot) on Nov 29, 2005 at 01:37 UTC

    Well, in his defense he did say: "Of course, there's lots I'd do to validate that attributes should exist, and so on, but this is simple-case code."

    -sauoq
    "My two cents aren't worth a dime.";