Subclassing Multiple Classes - MATLAB & Simulink (original) (raw)

Specify Multiple Superclasses

When inheriting from multiple classes, use the & character to indicate the combination of the superclasses:

classdef ClassName < SuperClass1 & SuperClass2

For more information on class syntax, see Subclass Syntax.

Class Member Compatibility

When you create a subclass derived from multiple superclasses, the subclass inherits the properties, methods, and events defined by all specified superclasses. If more than one superclass defines a property, method, or event having the same name, 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.

Here are various situations where you can resolve name and definition conflicts.

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:

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 you enhance superclasses in future versions and introduce new conflicts.

Reduce potential problems by implementing only one unrestricted superclass. In all other superclasses, all methods are

When using multiple inheritance, ensure that all superclasses remain free of conflicts in definition.