OK, "how to use it" and "how does it work" are very different questions. I'll leave the second point to monks who understand the internals of Perl better than I, and just try to give you a feel for the motivation behind inheritance.

Inheritance is a programming construct that's supported directly in object-oriented languages (such as Smalltalk) and can be retrofitted into some others (such as Perl). Basically, it addresses the situation where you've found some code that does almost everything that you need, but not entirely. In that situation, you have some choices:

The first technique is usually not available if somebody's paying you to write the code -- although if it's available, it may be the most expedient way of getting what you want done!

The second usually creates maintenance headaches because it breaks the link to the origignal. For example, suppose the original author finds a bug and publishes a fix. Now the person maintaining your code has to find out about the bug, then figure out whether and how the fix applies to your modified version. Or a spiffy new version comes out and now you have copy and paste all over again. (Many other scenarios are possible, but I just want to give you the flavor.)

The third option is what inheritance does. It lets you create new code that looks and acts like the old code (as a matter of fact, it calls the old code!), except where you add new stuff.

For example, say you found a great (Perl module, Java class, C++ library) called SuperCool that does 98% of what you want, but you just need to add a couple of things. With inheritance, what you can do is create a class that inherits from SuperCool called, say, HyperCool. This one has all the methods of SuperCool, and the ones you added, but you don't have to duplicate the code for SuperCools's methods. The languages that support OOP will figure out if a call to a method in HyperCool is actually for code written in SuperCool, and will dispatch to that code with the calling client program being none the wiser. The net result is that you're able to provide SuperCool's functionality, and add to it, in a maintenance-friendly way.

There is a lot more that can be said about the topic. This is a miniminal overview, but hopefully it'll allow you to understand the more advanced material.

HTH.


In reply to Re: Understanding what Inheriting is. by VSarkiss
in thread Understanding what Inheriting is. by Mr.T

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.