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

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

by Arunbear (Prior)
on Sep 28, 2017 at 18:18 UTC ( [id://1200300]=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?

You might have heard of the Single Responsibility Principle which says that a class should only have one job to do (or only one reason to change).

Your SMNPDevice is holding down two jobs i.e. being a base class and being a factory (a factory decides what type of objects to create). A cleaner design would be to just let SMNPDevice be a base class, and introduce a separate factory (essentially what Corion's example does).

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-19 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found