in reply to Understanding 'Multiple Inheritance'

Careful, B is an actual core module.

The OO competition for your subclass is a class which has-a instance of B and has-a instance of C as data members. It is fairly uncommon for multiple inheritance to make more sense than that kind of aggregation.

It may help decide if you reflect on whether A is-a B and A is-a C. Compare that to your answers to the same question with has-a substituted.

Because you justify the A class as a sort of opaque wrapper to keep users out of B and C, I suspect that aggregation will win. Your justification doesn't support a logical descent from B and C. An aggregate constructor based on your requirements will look something like this:

# omit @ISA dance sub new { my $class = shift; bless { Bobj => B->new(@_[0,1]), Cobj => C->new(@_[2,3]) }, $class; }
Again, don't really use 'B' as a package name, it's taken and will get very confusing.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Understanding 'Multiple Inheritance'
by punkish (Priest) on Mar 07, 2005 at 05:43 UTC
    Careful, B is an actual core module.
    Yes, I am am aware of that. Am just using A, B, C... as placeholders (too many Algebra lessons for my daughter).

    It may help decide if you reflect on whether A is-a B and A is-a C. Compare that to your answers to the same question with has-a substituted.

    Nice. Put that way, A has-a B and has-a C. Thanks for your aggregation code. I will work with that tact.

    That said, could I do something like...

    package A; use B; use C; use strict; sub new { my ($class) = @_; bless {}, $class; } sub make_B { my ($self) = shift; return new B(@_); } sub make_C { my ($self) = shift; return new C(@_); } ### and then, in my script... use A; my $a = A->new(); # $a has all the methods of A my $b = $a->make_B('a', 'b'); # now $b has all the methods of B my $c = $c->make_C('c', 'd'); # and $c has all the methods of C
    --
    when small people start casting long shadows, it is time to go to bed