just a thought

Peter Scott Peter at PSDT.com
Thu Feb 20 12:57:14 CST 2003


At 10:46 AM 2/20/03 -0800, 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.

Well, they're not really parents; that term is reserved for 
inheritance.  They're the delegates, or whatever they're called.

>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.

That's a neat model you have there.  I'm not sure that it really 
qualifies as delegation since you are not going via the delegating 
object; I think delegation is when you call a method on an object and 
it delegates it to another object that it contains.  So above you'd 
have to have

$object->fooperdooper;
$object->bazball;
$object->kindasorta;

and in the last case $object would have to decide which object to 
delegate it to.

See <http://search.cpan.org/perldoc?Class::Delegation>.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/




More information about the Victoria-pm mailing list