On Tue, Oct 01, 2002 at 04:01:26PM -0700, Michael Lazzaro wrote:
> 
> >On Tue, Oct 01, 2002 at 03:43:22PM -0400, Trey Harris wrote:
> >>You want something like
> >>
> >>  class Car is Vehicle renames(drive => accel)
> >>            is MP3_Player renames(drive => mp3_drive);
> 
> I *really* like this, but would the above be better coded as:
> 
>       class Car is Vehicle renames(drive => accel)
>               has MP3_Player renames(drive => mp3_drive);
> 
> .... implying a "container" relationship with automatic delegation?  
> Among the other considerations is that if you simply said
> 
>       class Car is Vehicle has MP3_Player;
> 
> the inheritance chain could assume that Car.drive === Vehicle.drive, 
> because is-a (inheritance) beats has-a (containment or delegation).  If 
> you needed to, you should still be able to call $mycar.MP3_Player.drive 
> to DWYM, too.

I don't think I like this. Assume that instead of an mp3 player my car
has a 007 CD autochanger.

then $car.drive is as we expect, Vehicle.drive, because inheritance beats
containment or delegation.

But I could get a nasty shock when I want to open the tray on the CD player,
call $car.eject, and the car fires me out through the sunroof.

I think that the first syntax

class Car::Q is Car renames(eject => ejector_seat)
                is CD_Player renames(drive => cd_drive);

makes it more clear that I'd like to pick and choose which methods
the composite object gets from which parent.

Nicholas Clark
-- 
Even better than the real thing:        http://nms-cgi.sourceforge.net/

Reply via email to