in reply to Re^3: SUPER in OOPerl is dumped with $self
in thread SUPER in OOPerl is dumped with $self

How can we work around when we have multiple inheritance?

Update

To be specific, the topic of discussion is how to workaround with SUPER so that Child will know who is the parent. On node "Re^3: SUPER in OOPerl is dumped with $self" monk pajout suggest some code to workaround with it. When there is multiple inheritence, its obvious that there are more than one parents and SUPER will be searching in @ISA. So question is, how the child will know who all are the parent(objects). How can I modify the solutions at "Re^3: SUPER in OOPerl is dumped with $self" to make the child, who all are its parent(objects)

  • Comment on Re^4: SUPER in OOPerl is dumped with $self

Replies are listed 'Best First'.
Re^5: SUPER in OOPerl is dumped with $self
by pajout (Curate) on Jul 03, 2007 at 14:24 UTC
    Yes, you are right. We cannot use SUPER as a reference to the instance of parent class, because it references parent class. There is no instance of parent class related with $self implicitly.

    Yes, Java is different from our perspective.

    How to handle multiple inheritance... To be open, I never had to do it. Anyway, do you mean class-inheritance or instance-inheritance?

Re^5: SUPER in OOPerl is dumped with $self
by dsheroh (Monsignor) on Jul 03, 2007 at 16:31 UTC
    Multiple inheritance is implemented in Perl by placing all the base classes into the derived class's @ISA. If an instance of the derived class receives a call to a method the derived class doesn't define, the classes listed in @ISA are searched in order from left to right.

    e.g., Given the class Chimera where @Chimera::ISA = qw(Lion Snake Eagle), calling $my_chimera->speak will look first for Chimera::speak, then Lion::speak, then Snake::speak, and finally Eagle::speak and execute whichever it finds first.

Re^5: SUPER in OOPerl is dumped with $self
by dsheroh (Monsignor) on Jul 03, 2007 at 20:10 UTC
    An object representing a child may or may not have objects representing its parents, but this has absolutely nothing to do with inheritance (multiple or otherwise) in the OO sense. As I said earlier, the different meanings of "parent" and "child" in the real-world context vs. the OO context appear to be confusing the issue here.

    Consider the following object model:

    Person --- Person::Child \-- Person::Adult
    Each Person::Child instance has an @parents property which holds one or more Person::Adult objects representing its parents (in the real-world sense), yet Person::Adult is not Person::Child's parent (in the OO sense).

    This example also answers the question of how to modify pajout's code to allow the child object to have an arbitrary number of parent objects (change the parent property to an array):

    sub parents { my $self = shift; push @{$self->{parents}}, @_ if @_; return @{$self->{parents}}; }
    ...but this is completely unrelated to multiple inheritance, so I question whether it's likely to tell you what you're actually trying to get at.