MATLAB Object-Oriented Programming

(Joyce) #1

Dispatching


In MATLAB classes, method dispatching is not based on method signature, as it is in C++
and Java code. When the argument list contains objects of equal precedence, MATLAB
uses the left-most object to select the method to call.


However, if the class of an argument is superior to the class of the other arguments,
MATLAB dispatches to the method of the superior argument, regardless of its position
within the argument list.


See “Class Precedence” on page 6-23 for more information.


Calling Superclass Method



  • In C++, you call a superclass method using the scoping operator:
    superclass::method

  • In Java code, you use: superclass.method


The equivalent MATLAB operation is method@superclass.


Other Differences


In MATLAB classes, there is no equivalent to C++ templates or Java generics. However,
MATLAB is weakly typed and it is possible to write functions and classes that work with
different types of data.


MATLAB classes do not support overloading functions using different signatures for the
same function name.


Object Modification


MATLAB classes can define public properties, which you can modify by explicitly
assigning values to those properties on a given instance of the class. However, only
classes derived from the handle class exhibit reference behavior. Modifying a property
value on an instance of a value classes (classes not derived from handle), changes the
value only within the context in which the modification is made.


The sections that follow describe this behavior in more detail.


Comparison of MATLAB and Other OO Languages
Free download pdf