I know about @ISA(class1 class2), so I'm not asking about that, but how to merge them seamlessly into 1 derived class.

My base class uses an array of multiple objects of same type and that's not a problem. To mix and use some shorthand:

package File_Entry { (has 3 routines, constructor & accessors): sub new([name,[rating]]); filename([name]) rating([rating]) } package File_Entries { use fields qw(__entries);
This is an array of "File_Entry's"; I consider this to be my "Base Class" even though it uses "File_Entry", it doesn't have an "ISA" relation. It supports 3 public methods & 1 "friend"ly method:
our $pckg_vars = __PACKAGE__; sub new () { my $class=$_[0]; my $s = {}; # base class starts/nothing $s->{$pckg_vars} = {}; bless $s, ref($class) || $class; $s->_entries_init; return $s; } sub ratings ([index,[rating]) #r/w accessor sub filenames([index]) #r/o accessor sub _add_entry(\$) #adds entry of type File_Entry
Other classes derive mostly hierarchically:
package Class2; our $pckg_vars = __PACKAGE__; sub new(){ my $class=$_[0]; my $s = "Base"->new(params).... my $s->{$pckg_vars} = {}; #'local' class var space bless $s,$class; return $s; ...} package Class3; our $pckg_vars => __PACKAGE__; sub new(){ my $class=shift; my $s = Class2->new(params)... my $s->{$pckg_vars} = {}; #class3 local vars bless $s,$class; return $s; ....} <etc>
At some point, I have a class with multiple inheritance....
{ package Entry_Display_In_Wins; use strict; our @ISA = qw(Entry_Ordering GUI_Glue); use base qw(Entry_Ordering); # and GUI_Glue, but base deficient use fields qw( __width __height __timer__ticked __timer__en +abled); ... but then I get to "new" sub new($) ... my ($class,$args) = @_; my $s= PreviousClass->new($args); confess "Fatal: memory for object $pckg_vars " . "busy (in use by someone else).\n" if (defined $s->{$pckg_vars}); $s->{$pckg_vars} = {}; bless $s, $class; ... $s->{$pckg_vars}->{'__GUI_Glue'}= GUI_Glue->new(...); return $s;
My problem is when I have 2 classes I am deriving from, I also have two "new" statements -- both with "pointers" or "handles" to objects of different types.

While I can rely on perl's inheritance mechanism to search my "ISA" for methods, calling anything under "Gui_Glue" needs the "handle" associated with GUI_Glue -- not the handle I got back from "PreviousClass";

So while I can rely on further derived classes to have access to both parents (via ISA), methods in either parent will only work with the specific "handle" I got back from their "new" constructors.

It's like I need a merge function: $s=class1->new() || class2->new()

Forgive my cluelessness, but it seems that the package using multiple inheritance must manually redirect all calls *through itself*, to the right methods. So if an upper method wants "create_window" (from 2nd base class GUI_Glue), then the MIUC (Multiple-Inheritance-Using-Class) needs to have it's own "create_window', then call its parent with the appropriately stored "handle" to the 2nd base class

Is there some way to "merge" the two base classes or does Entry_Display_In_Wins need to catch calls to, and function as a "Case" or "Switch" statement for each call to the 2nd-base class? Did I explain this clearly enough? Thanks! Linda


In reply to How to do multiple inheritance? by perl-diddler

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.