My base class uses an array of multiple objects of same type and that's not a problem. To mix and use some shorthand:
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:package File_Entry { (has 3 routines, constructor & accessors): sub new([name,[rating]]); filename([name]) rating([rating]) } package File_Entries { use fields qw(__entries);
Other classes derive mostly hierarchically: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
At some point, I have a class with multiple inheritance....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>
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.{ 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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |