I have been reading the various threads on multiple inheritance, but am still unclear. Perhaps someone can elucidate the following -- I want to create a class that inherits from two or more classes (the latter not created by me -- in other words, I can't modify the other packages). The pseudo code is like so --
package A; use B; use C; @ISA = qw/B C/; sub new { my ($class) = @_; bless {_foo => $_[1], _bar => $_[2],_baz => $_[3], _qux => $_[4],} +, $class; } ------------ package B; sub new { my ($class) = @_; bless {_foo => $_[1], _bar => $_[2],}, $class; } ------------ package C; sub new { my ($class) = @_; bless {_baz => $_[1], _qux => $_[2],}, $class; }
My intent is to hide the other packages, B, C, etc., from the user of my package. That way, the user of my package has to provide what I ask for (_foo, _bar, _baz, _qux), and all the methods from B, C, etc. become available. Just create
and $o will have all the methods of B and C as well.my $o = A->new('a', 'b', 'c', 'd');
update: fixed typos.
In reply to Understanding 'Multiple Inheritance' by punkish
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |