in reply to Skipping the middle man & the SUPER gotcha
It looks like your problem is that your inheritance is broken. In your example, Dad inherits from Grandpa, but then decides to replace hello() without calling the hello() in Grandpa. That's not a good thing necessarily. You may not see it in this very simple example, for for more complex real world things, Grandpa may need to run its hello() to do things to make everything else keep working. The sub-classes don't usually know about those things, and they shouldn't.
After that, you create a Me class that inherits from Dad. When it calls hello(), it gets the one from Dad. That's the way it should be because you said Me inherits from Dad. You shouldn't get to peek inside the @ISA for Dad to skip a level to call Grandpa::hello(). The @ISA may change, and if it does, you're hanged yourself.
Perl offers "no help in hard-coding method names" because you shouldn't be doing that. If you want to use inheritance, you should be inheriting the behaviour of the superclass. If you don't want that behaviour, why are you inheriting it instead of overriding it?
You may think you want this in certain situations, but eventually you'll get burned. When you don't let the entire chain do what they want to do, something is going to get out of sync because code doesn't run when it should. That's a terrible thing to have to track down.
Furthermore, if you're using SUPER:: outside of the internals of a class, you're probably not doing the right thing. A good design hides all that stuff at the user level.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Skipping the middle man & the SUPER gotcha
by tlm (Prior) on Apr 02, 2005 at 21:29 UTC | |
by merlyn (Sage) on Apr 02, 2005 at 22:18 UTC | |
by tlm (Prior) on Apr 03, 2005 at 01:49 UTC | |
by merlyn (Sage) on Apr 03, 2005 at 03:40 UTC | |
by Tanktalus (Canon) on Apr 03, 2005 at 00:51 UTC | |
by Mutant (Priest) on Apr 04, 2005 at 15:51 UTC |