in reply to It's a dog, but what kind? (polymorphism , in Perl OO)
$self= new $breed; . . . bless $self,$breed;
I don't think this will do what you want. This will re-bless the reference into the dog package, which means that if you asked for a 'cocker' breed, any methods that dog::cocker overrides won't be called. Instead, the methods in dog will be called. Update: Read the code wrong--ignore this pargraph.
Which is really unfortunate, since it could be quite useful to override the bark method in your final example. Instead of checking if this instance has a voice attribute that is true, the subclass would already know and Do The Right Thing. That's where polymorphism starts becoming powerful.
----
: () { :|:& };:
Note: All code is untested, unless otherwise stated
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: It's a dog, but what kind? (polymorphism , in Perl OO)
by blue_cowdawg (Monsignor) on Mar 23, 2004 at 21:30 UTC | |
by hardburn (Abbot) on Mar 23, 2004 at 21:36 UTC | |
by blue_cowdawg (Monsignor) on Mar 23, 2004 at 21:46 UTC |