Then any parent class that chooses to squirrel that away can add:package Cow; use base qw(Animal); __PACKAGE__->makes_sound_like('moo'); ...
Now the factory method can consult the locally prepared table, and can change the storage representation without all the derived classes being aware. In other words, this setup is far less maintainence, and far less typing the same thing twice or more.package Animal; sub makes_sound_like { my $class = shift; my $sound = shift; our %sound_registry; if (exists $sound_registry{$sound}) { croak "two animals want the sound $sound\n"; } else { $sound_registry{$sound} = $class; } }
At least, that's how I'd design it. {grin}
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
In reply to Re: Factory Pattern
by merlyn
in thread Factory Pattern
by tomazos
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |