| Next | February 2001 | Slide #20 |
Why use $hamlet->name when you could use $hamelet->{NAME} directly?
The method version allows a change of the underlying implementation
For example, we could make $hamlet into an anonymous array instead:
sub new {
my ($class) = @_;
bless [], $class;
}
sub name {
my $self = shift;
if (@_) { $self->[0] = shift }
return $self->[0];
}
This uses less space and time
If the program has $hamlet->{NAME}, it will break
Using the specified interface allows implementation changes
| Next | ![]() |
Copyright © 2001 M-J. Dominus |