in reply to Abstraction: Has far is to far?
The 'private' accessor has to know the name of the hash key, but the 'public' accessor doesn't. So, if you change foo to bar:package Foo; sub new { my $class = shift; my $self = { foo => 'bar', baz => 'qux', }; return bless $self, $class; } # 'private' method sub _get_foo { my $self = shift; return $self->{foo}; } # 'public' method sub get_foo { my $self = shift; return $self->_get_foo(); }
You don't have to track down as many places to change. There are still issues however, such as whether or not calling get_foo() to 'get bar' is acceptable. This is why proper feedback and designing is vital for large projects. However, as Murphy says, "Variables aren't. Constants don't". Also, i find it better to deprecate methods instead of outright removing/renaming them if you do have to change your interface accessor names:# 'private' has to change sub _get_foo { my $self = shift; return $self->{bar}; } # but 'public' doesn't sub get_foo { my $self = shift; return $self->_get_foo(); }
Just some food for thought ...sub get_foo { my $self = shift; carp "get_foo() is deprecated, use get_bar()"; return _get_bar(); } sub get_bar { my $self = shift; return $self->_get_bar(); }
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: (jeffa) Re: Abstraction: Has far is to far?
by jk2addict (Chaplain) on Aug 26, 2002 at 15:22 UTC |