| Next | Higher-Order Perl | 122 |
Why would you want to do that?
Consider this problem with conventional objects:
sub new {
my ($package, $name, $balance) = @_;
my $self = { NAME => $name, BALANCE => $balance };
bless $self => $package;
}
...
my $object = BankAccount->new('Fred', 100.00);
$object->{BALANCE} = 1000000000000.37;
Wasn't that data supposed to be encapsulated?
I guess it wasn't encapsulated very well
This is impossible with function objects
| Next | ![]() |
![]() |
Copyright © 2006 M. J. Dominus |