in reply to Re^3: Understanding 'Multiple Inheritance'
in thread Understanding 'Multiple Inheritance'
Polymorphism encourages encapsulation, but absolutely requires inheritance.Completely false.
? Not just "false" but "completely false"? So polymorphism neither encourages encapsulation nor requires inheritance?
This is not polymorphism, this is overloaded functions, as in multimethods of perl 6. Your methods are, more or less:
This is not polymorphism. Overloadable functions (same name, different contents) are usually found only in OO languages, but I don't think that this is causal. I think C may have overloadable functions in the not-too-distant future, if it doesn't already in the latest spec.sub quack(RubberDuck $self) { ... } sub quack(Mallard $self) { ... }
package RubberDuck; sub new { bless {}, shift } sub make_noise { print "Plug yer ears!\n"; $_[0]->quack(); } sub quack { print "Squeak!\n" } sub DESTROY { print "RubberDuck goes back in the toybox.\n" } package Mallard; our @ISA = qw(RubberDuck); 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->make_noise(); }
This is polymorphism. The parent class calls a function in the parent class, but the derived class gets to intercept it and do stuff with it. That stuff may include calling the parent class, or, as in this example, it may not.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Understanding 'Multiple Inheritance'
by chromatic (Archbishop) on Mar 07, 2005 at 22:06 UTC | |
|
Re^5: Understanding 'Multiple Inheritance'
by tilly (Archbishop) on Mar 08, 2005 at 02:08 UTC |