Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Understanding what Inheriting is.

by clemburg (Curate)
on Aug 13, 2001 at 15:05 UTC ( [id://104417]=note: print w/replies, xml ) Need Help??


in reply to Understanding what Inheriting is.

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

Replies are listed 'Best First'.
Re (tilly) 2: Understanding what Inheriting is.
by tilly (Archbishop) on Aug 13, 2001 at 16:01 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://104417]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-18 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found