MATLAB Object-Oriented Programming

(Joyce) #1
calls the DocPolynom plus method (which converts the double, 1, to a DocPolynom
object and then implements the addition of two polynomials). The DocPolynom class has
precedence over the built-in double class.

Defining Precedence


You can specify the relative precedence of classes defined with the classdef syntax by
listing inferior classes in a class attribute. The InferiorClasses property places a class
below other classes in the precedence hierarchy. Define the InferiorClasses property
in the classdef statement:
classdef (InferiorClasses = {?class1,?class2}) myClass

This attribute establishes a relative priority of the class being defined with the order of
the classes listed.

Location in the Hierarchy

If objectA is above objectB in the precedence hierarchy, then the expression

objectA + objectB

calls @classA/plus.m. Conversely, if objectB is above objectA in the precedence
hierarchy, then MATLAB calls @classB/plus.m.

See Also


More About



  • “Dominant Argument in Overloaded Graphics Functions” on page 9-49

  • “Class Precedence” on page 6-23


9 Methods — Defining Class Operations

Free download pdf