in reply to Re: Re: OO Perl: calling a constructor within a class
in thread OO Perl: calling a constructor within a class
I did have some discussion with tye about can, and at the time he convinced me to use isa instead: ... $me->isa('UNIVERSAL').if ( ref $me and $me->can('can') ){ .....
More importantly, reading perlbot I realised that all that caution about bless is unnecessary. So I rephrase my advise above:
There is nothing special about constructors other than that they bless a variable. Since you are allowed to rebless a variable, just call the constructors at will.In perlbot you can find more info and an example of nested constructors.
Reblessing assumes that the caller knows what (s)he is doing and that the constructor should always return an object of its own class. This antagonizes the logic behind bless-checking. The reblessing approach is the most flexible one, as constructors do not have to make assumptions about which class the returned objects should be in.
This in turn made me realise that multiple inheritance could, with a little caution, even apply to the object's data. Just call both constructors and merge the resulting anonymous arrays. Problems will arise when the inherited classes use the same hash-entries for different purposes or when different types of variables are used, of course. At the end, one just reblesses the anonymous hash.
Jeroen
"We are not alone"(FZ)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Reblessing (was: OO Perl: calling a constructor within a class)
by dragonchild (Archbishop) on Sep 27, 2001 at 17:39 UTC | |
by tilly (Archbishop) on Sep 27, 2001 at 21:05 UTC |