Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Can a class constructor create an instance of a derived class and return it? Or, can objects transmute into other objects?

by alexander_lunev (Pilgrim)
on Sep 28, 2017 at 21:37 UTC ( [id://1200320]=note: print w/replies, xml ) Need Help??


in reply to Can a class constructor create an instance of a derived class and return it? Or, can objects transmute into other objects?

If i understand you correctly, it's the "Factory method" pattern case. I'm using it for storage abstraction.

package Storage::Factory; { use Storage::SQLite; use Storage::MySQL; sub new { my $class = shift; my $opt = {@_}; return Storage::SQLite->new(file => $opt->{dsn}) if $opt->{typ +e} eq 'sqlite'; return Storage::MySQL->new(dsn => $opt->{dsn}) if $opt->{type} + eq 'mysql'; } } 1; use Storage::Factory; my $storage = Storage::Factory->new(%{ $self->plugin('Config')->{db} } +)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 05:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found