I have a suite of classes (Thingy, Thingy::Cog, Thingy::Handle, Thingy::Ramp, etc.) that can be inherited from so that their methods can be overridden. Thing is (no pun intended), Thingy objects need to generate Thingy::Cog objects. Therefore, when a class derives from Thingy (such as MyThingy) it should auto-generate inheriting classes with the same prefix (autovivifying MyThingy::Cog, MyThingy::Handle, etc.).
I'd rather not hard-code more than I have to in this case, unless a purely dynamic solution is disgusting to look at and code.
Update: I apologize if I was unclear. Here's a better explanation. A Thingy object produces a Thingy::Cog object. If I sub-class Thingy as MyThingy, I want the MyThingy object to attempt to create a MyThingy::Cog object instead of the hardcoded Thingy::Cog object. If MyThingy::Cog doesn't exist, then Thingy::Cog should be the class used.
What this means is that I have this code...
and I want to make it extensible when Thingy is subclassed (and Thingy::Cog is potentially subclassed). I could dopackage Thingy; sub get_cog { my ($self) = @_; return Thingy::Cog->new; }
but that breaks if the person subclassing Thingy has not also subclassed Thingy::Cog.sub get_cog { my (@self) = @_; return( (ref($self) . "::Cog")->new ); }
In reply to Inheritance in a Suite of Modules by japhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |