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.
In reply to Re^3: Understanding 'Multiple Inheritance'
by chromatic
in thread Understanding 'Multiple Inheritance'
by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |