in reply to OO Getters/Setters
# Assume I have foo, bar, and baz as my attributes my $x = $self->foo; # This retrieves the value in foo $self->foo(123); # This sets foo to 123 (and returns $self, to all +ow for: $self->foo(123) # chaining of mutator calls ->bar(456);
Now, I have used generic set/get routines. We had a set() and a get(), that took attribute names. So, you would have:
my %values; @values{qw(foo bar baz)} = $self->get(qw(foo bar baz)); $self->set( foo => 123, bar => 456, );
Except, there are a few issues. How do you handle misnamed attributes? What about attributes whose values are arrayrefs? It gets messy. And, it's even worse if you have a single method for doing all accessor/mutator functionality. Personally, I'd recommend against this. Maintainability will suffer.
------
We are the carpenters and bricklayers of the Information Age.
Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: OO Getters/Setters
by boo_radley (Parson) on Dec 31, 2003 at 20:48 UTC | |
by stvn (Monsignor) on Jan 01, 2004 at 01:59 UTC |