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?? |
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).
In Section
Seekers of Perl Wisdom
|
|