Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: It's a dog, but what kind? (polymorphism , in Perl OO)

by adrianh (Chancellor)
on Mar 23, 2004 at 20:21 UTC ( #339168=note: print w/replies, xml ) Need Help??

in reply to It's a dog, but what kind? (polymorphism , in Perl OO)

What if I could make the base class dog smarter and have it instantiate the subclasses for me?

For those who don't know this approach of having a single class instantiate different subclasses depending on the arguments is a common design pattern called an Abstract Factory (or sometimes Kit). If you keep an eye out you'll start seeing it everywhere (e.g. DBI instantiates different classes depending on the arguments to connect).

Class::Factory provides a little framework for rolling this sort of stuff together if you don't want to do it yourself.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2021-05-16 22:36 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (152 votes). Check out past polls.