Subclassing from Multiple Classes

Class Member Compatibility

When you create a subclass derived from multiple classes, the subclass inherits the properties, methods, and events defined by all specified superclasses. If a property, method, or event is defined by more than one superclass, there must be an unambiguous resolution to the multiple definitions. You cannot derive a subclass from any two or more classes that define incompatible class members.

There are a variety of situations where name and definition conflicts can be resolved, as described in the following sections.

Property Conflicts

If two or more superclasses define a property with the same name, then at least one of the following must be true:

Method Conflicts

If two or more superclasses define methods with the same name, then at least one of the following must be true:

Event Conflicts

If two or more superclasses define events with the same name, then at least one of the following must be true:

Using Multiple Inheritance

Resolving the potential conflicts involved when defining a subclass from multiple classes often reduces the value of this approach. For example, problems can arise when superclasses are enhanced in future versions and might introduce new conflicts. These potential problems might be reduced if only one superclass is unrestricted and all other superclasses are classes in which all methods are abstract and must be defined by a subclass or inherited from the unrestricted superclass.

In general, when using multiple inheritance, you should ensure that all superclasses remain free of conflicts in definition.

See Defining a Subclass for the syntax used to subclass multiple classes.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS