just a thought

abez abez at abez.ca
Thu Feb 20 13:04:19 CST 2003


Checkout:
http://cedar.csc.uvic.ca/twiki/kienle/pub/SENG430/CourseMaterial/IaS_handout.pdf

Perl can already handle multiple inheritance so if you're using inheritance
use that. Delegation is good for situations like say we have the structure

    Person
      |
   +--+----------+
   |             |
Engineer       Janitor

We the problem here is that even if a Janitor gets training they can never be
an engineer.

Where as if Person delegates to a Job the system is much more flexible.

    Person---------------------->Job
    			          |
                               +--+----------+
                               |             |
                           Engineer       Janitor

In languages like C++ or Java inheritance is usually faster than delegation.
In a language like Perl I don't think it's much of an issue.

In something like Java implementing a interface then delegating to an object
made specifically to implement that interface would be similar to multiple
inheritance yes. For instance PropertyChangeSupport provides event firing
functionality to your class without the use of inheritance.

On Thu, 20 Feb 2003, nkuipers wrote:

> Yesterday I inadvertently illustrated use of "delegation" in Perl, in a
> roundabout way to establish inheritance in my BIO:: namespace.  Peter, in
> addition to showing me the easy way to Perl inheritance, mentioned that there
> is a raging controversy among OO purists about when (if ever?) delegation
> should be used.  I am thinking that this is a tremendously useful way to
> implement multiple inheritance.  In the child class constructor, you could
> have a key for each parent name, where the value is the call to that parent's
> constructor.  It would then be very easy to call any method from any parent,
> right from the child object:
>
> $object->{super1}->fooperdooper();
> $object->{super2}->bazball();
>
> You would also allow easy, hardcoded access to identically named methods in
> different parents:
>
> $object->{super1}->kindasorta();
> $object->{super2}->kindasorta();
>
> Am I more or less correct in my "realizations" about delegation?  If so, I
> find it to be really quite exciting.
>
> Cheers all,
>
> Nathanael
>

-- 
abez ------------------------------------------
http://www.abez.ca/ Abram Hindle (abez at abez.ca)
------------------------------------------ abez



More information about the Victoria-pm mailing list