in reply to How to implement a Design Pattern/ Strategy??

Well, I haven't looked too closely, but from the short if/else section, you want to start by making functions, like this
if ($category_id eq "all") { push @all_matches, SomethingAll(...); } elsif ($category_id eq "subj") { push @all_matches, SomethingSubj(...); }
which you would later turn into a dispatch table
my %dispatch_table = ( all => \&SomethingAll subj => \&SomethingSubj _default => \&SomethingDefault ); ... my $callback = $dispatch_table{$category_id} || $dispatch_table{_defau +lt}; push @all_matches, $callback->(...);
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.

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

    Thanks a lot for breaking it down. You make it sound like I could almost do it. I will try implementing your steps.