MATLAB Object-Oriented Programming

(Joyce) #1

Method Invocation


In this section...
“Determining Which Method Is Invoked” on page 9-15
“Referencing Names with Expressions—Dynamic Reference” on page 9-17
“Controlling Access to Methods” on page 9-19
“Invoking Superclass Methods in Subclass Methods” on page 9-19
“Invoking Built-In Functions” on page 9-20

Determining Which Method Is Invoked


When MATLAB invokes an ordinary method that has an argument list, it uses the
following criteria to determine which method to call


  • The class of the leftmost argument whose class is not specified as inferior to any other
    argument's class is chosen as the dominant class and its method is invoked.

  • If this class does not define the called method, then a function with that name that is
    on the MATLAB path is invoked.

  • If no such function exists, MATLAB issues an error indicating that the dominant class
    does not define the named method.


Dominant Argument

MATLAB uses dominant argument dispatching to determine which version of a method to
call. During method dispatching, MATLAB determines the dominant class from among the
arguments in the call. In general, all MATLAB classes defined using the classdef syntax
have equal precedence for purposes of method dispatching.

Classes defined using the classdef syntax take precedence over these MATLAB classes:

double, single, int64, uint64, int32, uint32, int16, uint16, int8, uint8, char,
string, logical, cell, struct, and function_handle.

In general, when two or more objects are part of the argument list, the method defined
for the class of the left-most object is invoked. However, user-defined classes can specify
the relative dominance of specific classes. For information, see “Class Precedence” on
page 6-23.

Method Invocation 9-

Free download pdf