in reply to Method of child module called by parent
Hello gzartman, and welcome to the Monastery!
I'd like to be able to call methods from the child class as if they were in the parent class
You have that back-to-front! Child classes inherit from their parents; parent classes ought to have no knowledge of their children. So when you have code like this:
package parentClass; use parentClass::childClass;
it’s almost always a symptom of a faulty OO design.
I've been working on a perl module and found that it was getting a big unwieldy, so decided to spin off a few child classes to my main class to help organization and what not.
A child class specialises its parent in a way that makes for an asymmetrical ISA relationship. For example, owl specialises bird, because an owl ISA bird (but a bird is not necessarily an owl). So, anything a bird can do, an owl can do too (but most likely in a distinctively owlish way). And an owl can do things other birds can’t: for example, $owl->hunt_at_night() or $owl->hoot() make a lot more sense than $sparrow->hunt_at_night() or $sparrow->hoot(). So it makes little sense to give hunt_at_night or hoot methods to package bird; and still less sense to try to allow a bird (which could be an eagle, a toucan, or a dodo) to hoot in the way owls do!
I suspect what you’re looking for is a helper class which your parent class accesses via a HASA or USES relationship. But in the absence of concrete details it’s hard to give more definite advice.
By the way:
Please put your code in <code> ... </code> tags; see Markup in the Monastery.
The standard convention is to begin a package name with an uppercase letter: ParentClass, ParentClass::ChildClass;.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Method of child module called by parent
by gzartman (Novice) on Dec 26, 2014 at 09:00 UTC | |
by Athanasius (Archbishop) on Dec 26, 2014 at 09:33 UTC | |
by gzartman (Novice) on Dec 27, 2014 at 01:32 UTC | |
by three18ti (Monk) on Dec 31, 2014 at 21:30 UTC | |
by Athanasius (Archbishop) on Jan 01, 2015 at 04:06 UTC | |
by three18ti (Monk) on Jan 02, 2015 at 16:49 UTC | |
by Anonymous Monk on Dec 26, 2014 at 16:43 UTC |