No such thing as a small change | |
PerlMonks |
Re: Factory classes in Perlby choroba (Cardinal) |
on Jan 08, 2021 at 22:34 UTC ( [id://11126635]=note: print w/replies, xml ) | Need Help?? |
Making the example a bit more realistic, imagine the two types of Reindeer are in fact a *nix Reindeer and a MSWin Reindeer. You want to build the one that's compatible with the OS, but the final product should work on both the platforms transparently. Basically, any time you write a package that instantiates different classes based on something, you should consider the factory pattern.
map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
In Section
Seekers of Perl Wisdom
|
|