in reply to How to implement a Design Pattern/ Strategy??
which you would later turn into a dispatch tableif ($category_id eq "all") { push @all_matches, SomethingAll(...); } elsif ($category_id eq "subj") { push @all_matches, SomethingSubj(...); }
OO not required. When deciding which function to call requires something more complicated than a simple string comparison (key lookup), you'll benefit more from using object-oriented-programming.my %dispatch_table = ( all => \&SomethingAll subj => \&SomethingSubj _default => \&SomethingDefault ); ... my $callback = $dispatch_table{$category_id} || $dispatch_table{_defau +lt}; push @all_matches, $callback->(...);
perl Moose Strategy Design Pattern -> https://secure.wikimedia.org/wikibooks/en/wiki/Computer_Science_Design_Patterns/Strategy#Perl
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to implement a Design Pattern/ Strategy??
by jonc (Beadle) on Jun 12, 2011 at 17:57 UTC |