I'd like to follow lemming in suggesting that you should read Object Oriented Perl from Damian Conway. It contains a very good introduction to objects "in general".

As VSarkiss noted, "what inheriting really is" and "how inheriting really works" might be two questions: what inheritance is, conceptually, vs. how inheritance is implemented in Perl.

This makes a real difference, as Perl implements inheritance differently than, e.g., C++ or Java.

Basically, "inheriting" from a class means that you can use operations (methods) and access variables (attributes, properties) that you have not defined in the inheriting class, but which are defined in the class you inherited from or one of its ancestor classes.

Now, how do you implement this?

One common implementation method (e.g., C++, Java), sometimes called "implementation inheritance", is to embed an object of the parent class in every object of the inheriting class. When the object of the inheriting class is now asked for an operation or variable that it does not know about, it forwards the request to the embedded parent class object. (This is fun with multiple inheritance, see C++ "virtual base class").

Another common implementation method (e.g., Perl, Smalltalk), sometimes called "interface inheritance", is to record somewhere information about the relationship between the inheriting class and its parent class(es), and to provide a language mechanism that uses this information to find the missing operations or variables at runtime. That is, when you invoke an operation or access a variable via an object, and the object does not know about it, some mechanism will kick in and search the parent classes for the operation or variable until it finds it.

In Perl, you inherit only methods. Camel III, p. 321 says: "This is how Perl implements inheritance: each element of a given package's @ISA holds the name of another package, which is searched when methods are missing."

Christian Lemburg
Brainbench MVP for Perl
http://www.brainbench.com


In reply to Re: Understanding what Inheriting is. by clemburg
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.