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?
That would simply be another way to do it. One is multiple inheritence, the other is delegation. Both should be in the language. > 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. This, too, is another way to do it, but I like Trey's original solution much better. When you use your MP3 Car as a Vehicle, the Vehicle methods win. When you use it like an MP3_Player, the MP3_Player methods win. No need to expose the underlying MP3_Player object to the user. YMMV. -- Michael G. Schwern <[EMAIL PROTECTED]> http://www.pobox.com/~schwern/ Perl Quality Assurance <[EMAIL PROTECTED]> Kwalitee Is Job One List context isn't dangerous. Misquoting Gibson is dangerous. -- Ziggy