It might even be reasonable to expect "$self->SUPER" to do this.

Just to extend my example a little to include that, let's add another method to AngryDog:

sub pull_tail { $self->SUPER; bite(); }
In real-world logic, it's obvious that the AngryDog should still growl before biting when its tail is pulled, not bark.

It's been quite a while since I last used C++, but I talked to a Java junkie friend the last time something like this came up and he confirmed that Java handles it the same as Perl does. I'm pretty sure C++ (and, for that matter, any language that supports polymorphism) would also behave similarly. To do otherwise would render abstract classes/methods pointless. (Derived class overrides the abstract method, base class method calls the abstract method, and... either nothing happens or an exception is thrown unless it calls the derived class's version instead of the base version.)

But, yeah, I do agree that inheritance looks like an obvious candidate, but dragonchild's AUTOLOAD-based solution is surely both the slickest solution and the one which requires the least code to do what you want.


In reply to Re^3: Overriding methods and Inheritance by dsheroh
in thread Overriding methods and Inheritance by bamaindk

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.