in reply to OOP By Any Other Name
Using a hash in that fashion is generally referred to as dispatching and the hash is a "dispatch table". Contrast the technique with more usual Perl OO:
use strict; use warnings; package Counter; sub new { my ($class, $start) = @_; return bless {count => $start}, $class; } sub add { my ($self, $value) = @_; $self->{count} += $value; } sub get { my ($self) = @_; return $self->{count}; } package main; my $ctr = Counter->new (7); print "Start: " . $ctr->get () . "\n"; $ctr->add (3); print "End: " . $ctr->get () . "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: OOP By Any Other Name
by Anonymous Monk on Feb 26, 2011 at 02:09 UTC | |
by GrandFather (Saint) on Feb 26, 2011 at 02:57 UTC | |
by tilly (Archbishop) on Feb 26, 2011 at 03:02 UTC | |
by chromatic (Archbishop) on Feb 26, 2011 at 03:08 UTC | |
by ikegami (Patriarch) on Feb 26, 2011 at 07:31 UTC |