in reply to Re^2: Understanding 'Multiple Inheritance'
in thread Understanding 'Multiple Inheritance'
Polymorphism encourages encapsulation, but absolutely requires inheritance.
Completely false.
package RubberDuck; sub new { bless {}, shift } sub quack { print "Squeak!\n" } sub DESTROY { print "RubberDuck goes back in the toybox.\n" } package Mallard; sub new { bless {}, shift } sub quack { print "Quack!\n" } sub DESTROY { print "Mallard flies away.\n" } package main; for my $duck_class (qw( RubberDuck Mallard )) { my $duck = $duck_class->new(); $duck->quack(); }
Duck typing, without inheritance.
Polymorphism has ever so much more to do with method dispatch and type equivalence (in languages that care about such things and in situations where it matters) than it does about inheritance, which is merely an implementation detail of how to reuse code and to mark type equivalence in some cases.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Understanding 'Multiple Inheritance'
by Tanktalus (Canon) on Mar 07, 2005 at 21:04 UTC | |
by chromatic (Archbishop) on Mar 07, 2005 at 22:06 UTC | |
by tilly (Archbishop) on Mar 08, 2005 at 02:08 UTC |