oo monks,

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; }
  1. Is the above do-able?
  2. Is this even good practice?
  3. If not, what is a better way of doing this?

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

my $o = A->new('a', 'b', 'c', 'd');
and $o will have all the methods of B and C as well.

update: fixed typos.

--
when small people start casting long shadows, it is time to go to bed

In reply to Understanding 'Multiple Inheritance' by punkish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.