There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Your question's a bit vague so I may be off chasing untamed ornithoids here; you might provide some more concrete, actual code and get a more relevant answer. That caveat aside . . . It may be a side effect of your example wording but that almost sounds more like you want to model a has-a relationship rather than is-a. A Robo has an Arm, Feet, and a Head (of whatever cardinalities); but the whole in and of itself isn't a more specialized type of Arm. You'd then set up some sort of delegation on the Robo instance so that when you call aa Arm method it calls that method on the Arm instance belonging to it instead. If you're using Moose or the like there's going to be a handles declaration which you can say that calls to some set of methods should be forwarded to be called on the value in that slot. See Moose::Manual::Delegation for more details on wiring that up. You then don't need to worry about chaining superclass constructors and what not, you just create your part instances and pass those components to the containing class' constructor. Edit: Tweaked wording a bit. This SO thread (specifically the first answer's examples) may make more clear what I'm saying WRT inheritance versus composition.
The cake is a lie. In reply to Re: How to sub class-es
by Fletch
|
|