Re: multiple inheritance and instance data?
- From: Peter Scott <Peter@xxxxxxxx>
- Date: Thu, 29 Mar 2007 14:07:53 GMT
On Thu, 29 Mar 2007 14:12:54 +0100, bugbear wrote:
I would like to have a class which has the behaviour[...]
of 2 more primitive classes.
But I can't see, if BOTH parent classes
have constructors that return a blessed
object (e.g. a the typical hash reference),
what I'm meant to do in my child
class.
It's not that both parent constructors return blessed objects that's the
problem (what else would they do?).
It's whether the parent constructors do anything besides creating empty
blessed hashrefs.
That's why it's a best practice for constructors to create empty objects
and nothing else.
You write a constructor in the child that blesses an object into your
child class. Then you have to inspect the constructors of your parents to
see what they're doing. If they both follow best practice, you need do
nothing else. If one of them is well behaved and the other isn't, you can
instead call the constructor on the not-well-behaved one and then rebless
the returned object into your class. If they're both not well behaved,
you probably have to cut and paste.
This is one of the uglier things about Perl O-O.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
.
- Follow-Ups:
- Re: multiple inheritance and instance data?
- From: bugbear
- Re: multiple inheritance and instance data?
- References:
- multiple inheritance and instance data?
- From: bugbear
- multiple inheritance and instance data?
- Prev by Date: Re: HowTo parse huge Files
- Next by Date: Re: HowTo parse huge Files
- Previous by thread: multiple inheritance and instance data?
- Next by thread: Re: multiple inheritance and instance data?
- Index(es):
Relevant Pages
|
|