Perl6 Object Oriented Cookbook (v0.2.1)  
Section 4: Inheritance  
 
Recipe 4.1: Declaring Multiple Inheritance
Last Updated: Sep 8, 2003
Status: Very Likely
      Previous Page   Next Page

How important is this problem to you?
  (Login to Vote)
3.67 Rating, 3 Votes  

How acceptable is the proposed solution?
  (Login to Vote)
3.00 Rating, 1 Vote  

Problem:  

You want your class to inherit from more than one parent class.

Solution:  

Specify a list after is:

class MyClass is Parent1 is Parent2 is Parent3 {
    ...
}

Discussion:

Perl6 supports multiple inheritance. To inherit from multiple parent classes, just specify each of those classes in the class declaration, as above.

Order is important. When searching through the parents of a class (to find the implementation of a method, for example), parents are always searched left-to-right. If a method exists in Parent1, it will take precedence over any method of the same name in Parent2, etc.

Issue: Are inheritance trees searched depth-first, as before? Any way around that?


Log In to Comment


Login / Edit User Info -- Copyright © 2002 Cognitivity -- Previous Page   Next Page