Specifying Class Precedence

InferiorClasses Attribute

You can specify the relative precedence of user-defined classes using the class InferiorClasses attribute. Assign a cell array of class names (represented as meta.class objects) to this attribute to specify classes that are inferior to the class you are defining. For example, the following classdef declares that myClass is dominant over class1 and class2.

classdef (InferiorClasses = {?class1,?class2}) myClass

The ? operator combined with a class name creates a meta.class object. This syntax enables you to create a meta.class object without requiring you to construct an actual instance of the class.

MATLAB built-in classes are always inferior to user-defined classes and should not be used in this list.

The built-in classes include: double, single, char, logical, int64, uint64, int32, uint32, int16, uint16, int8, uint8, cell, struct, and function_handle.

Dominant Class

MATLAB defines a class as dominant when evaluating expression involving objects of more than one class. The dominant class determines which method MATLAB calls and the class of arrays that are form by combining objects of different classes, assuming MATLAB convert to inferior objects to the dominant class. See Concatenating Objects of Different Classes for more information on creating object arrays.

More Information

See Determining Which Method Is Invoked for more on how the MATLAB classes dispatch when evaluating expressions containing objects.[/important]
See Class Precedence and MATLAB Path for information on how the location of a class definition on the MATLAB path determines its precedence.[/important]

[important]See Working with Meta-Classes for information on meta-class objects.[/important]

No Attribute Inheritance

Subclasses do not inherit a superclass InferiorClasses attribute. Only instances of the classes specified in the subclass InferiorClasses attribute are inferior to subclass objects.

You may also like...