Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Factory classes in Perl

by choroba (Cardinal)
on Jan 08, 2021 at 22:34 UTC ( [id://11126635]=note: print w/replies, xml ) Need Help??

in reply to Factory classes in Perl

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]

Replies are listed 'Best First'.
Re^2: Factory classes in Perl
by Bod (Parson) on Jan 11, 2021 at 22:52 UTC
    Making the example a bit more realistic

    What??? You don't have Robo-Reindeer pulling your sleigh?

    are in fact a *nix Reindeer and a MSWin Reindeer

    Ah yes!
    I totally understand when a Factory Class would be useful now. Not necessarily because of what modules are or are not installed but because of the environment in which the script might find itself with different OS, hardware, drivers or even other software...


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11126635]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-06-18 17:43 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.