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.

--
brian d foy <brian@stonehenge.com>

In reply to Re: Skipping the middle man & the SUPER gotcha by brian_d_foy
in thread Skipping the middle man & the SUPER gotcha by tlm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.