in reply to Re^3: Object Constructors - Advice of experienced OO Perl Monks
in thread Object Constructors - Advice of experienced OO Perl Monks
package MultiColoured; our @ISA = qw /Red White Blue/; sub new {my $self = Red->new; bless $self, shift} sub init { my $self = shift; $self->Red::init(...); $self->White::init(...); $self->Blue::init(...); } ... package main; my $obj = MultiColoured->new->init(...);
That doesn't mean MI is always possible. If in the above example Red assumes objects are hashrefs, and Blue assumes arrayrefs, MI isn't going to work. But if all the classes assume hashrefs (as most objects do), and you don't have clashes with the hashkeys, this is going to work.
But if you need to call the constructor to initialize the object, MI is going to fail.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Object Constructors - Advice of experienced OO Perl Monks
by izut (Chaplain) on Oct 06, 2005 at 16:24 UTC | |
by izut (Chaplain) on Oct 06, 2005 at 16:36 UTC | |
by Perl Mouse (Chaplain) on Oct 06, 2005 at 16:46 UTC | |
by Perl Mouse (Chaplain) on Oct 06, 2005 at 16:28 UTC |