in reply to Understanding 'Multiple Inheritance'
and then initialization routines like this:sub new { bless {}, shift; }
your package could look like:package B; sub init { my $self = shift; @$self {qw /_foo _bar/} = @_; } sub init { my $self = shift; @$self {qw /_baz _qux/} = @_; }
Of course, it gets worse if one or more of the packages uses a filehandle, or an array to implement to object, or if two of the inheriting classes use the key (but to find out, you have to break encapsulation).package C; use A; use B; our @ISA = qw /B C/; sub new {bless {}, shift} sub init { my $self = shift; $self -> B::init(@_[0, 1]); $self -> C::init(@_[2, 3]); }
In short, multiple inheritance in Perl is only possible if all of the classes you inherit have been implemented with this in mind (most classes don't - noone really teaches for this possibility, it's much easier to dismiss it with the statement that multiple inheritance is not done), or if you are lucky and willing to break encapsulation.
It seems that for your B and C, you're lucky, and can do it by breaking encapsulation.
As for question 3, sometimes it's good to admit defeat, and use a language with better OO support than Perl. (Which are easy to find, as it's hard to find a language with worse support)
|
|---|