in reply to Re: how do I do multiple inheritance
in thread how do I do multiple inheritance

The problem with calling multiple constructors is that it results in an object that only contains the results of the last constructor. What is really needed is a seperation of the creation and initialization steps in each class.

Here is the method I use (essentially a cut and paste from Chapter 6 of Damian Conway's excellent book Object Oriented Perl) as it applies to this particular problem:
#!/usr/bin/perl -w use strict; use Employee; my $hid = Employee->new; print "My gender is " . $hid->gender() . "\n"; print "My name is " . $hid->fullname() . "\n"; package Employee; use strict; use _Initializable; use Person; use Gender; @Employee::ISA = qw( _Initializable Person Gender ); sub _init { my $self = shift; $self->Person::_init(); $self->Gender::_init(); } 1; package Person; use strict; use _Initializable; @Person::ISA = qw( _Initializable ); sub _init { my $self = shift; $self->{FULLNAME} = "Robert Walkup"; } sub fullname { my $self = shift; return $self->{FULLNAME}; } 1; package Gender; use strict; use _Initializable; @Gender::ISA = qw( _Initializable ); sub _init { my $self = shift; $self->{GENDER} = "MALE"; } sub gender { my $self = shift; return $self->{GENDER}; } 1; package _Initializable; use strict; sub new { my $class = shift; my $self = {}; bless $self, ref($class) || $class; $self->_init(); return $self; } 1;
As you can see, the only major change is the addition of the _Initializable class to handle the creation of new objects, and the _init methods to initialize said objects. For any method other than a constructor, the options listed by lachoy above should work as advertised.

Vavoom

Replies are listed 'Best First'.
Re: Re: Re: how do I do multiple inheritance
by lachoy (Parson) on Jan 25, 2002 at 08:02 UTC

    Actually, the aforementioned Class::Base will do this for you automatically, and you won't need to specify the _init() method of your parents along the way. Sweet.

    Chris
    M-x auto-bs-mode