in reply to Abstraction: Has far is to far?

If you don't mind the performance hit, try to access your hash keys through methods only. That way, if you change the the name of the key, you should only need to change it two or three times - once in the constructor, and once for get/set methods:
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(); }
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:
# '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(); }
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:
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(); }
Just some food for thought ...

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

    Thanks for the tap of the ClueStick. If I want to access a modules internal hash data $self->{'data'}, I should really be using a accessor methods; public, private or otherwise. That in itself seems like overkill when I can just use the hash, but it's definately how I should be doing it.

    P.S. OT. Nice Kit.
    I prefer the 5-paradiddle in 4 over 6 myself..

    | R-RR-  R-RR-  R-RR-  R-RR-  |
    | -L--L  -L--L  -L--L  -L--L  |
    |
    | R    R    R    R    R    R  |