MATLAB Object-Oriented Programming

(Joyce) #1
Behavior Categories

When you call an inherited method on a subclass of a built-in class, the result depends on
the nature of the operation performed by the method. The behaviors of these methods fit
into several categories.


  • Operations on data values return objects of the superclass. For example, if you
    subclass double and perform addition on two subclass objects, MATLAB adds the
    numeric values and returns a value of class double.

  • Operations on the orientation or structure of the data return objects of the subclass.
    Methods that perform these kinds of operations include, reshape, permute,
    transpose, and so on.

  • Converting a subclass object to a built-in class returns an object of the specified class.
    Functions such as uint32, double, char work with subclass objects the same as they
    work with built-in objects.

  • Comparing objects or testing for inclusion in a specific set returns logical or built-in
    objects, depending on the function. Functions such as isequal, ischar, isobject
    work with subclass objects the same as they work with superclass objects.

  • Indexing expressions return objects of the subclass. If the subclass defines properties,
    then default indexing no longer works. The subclass must define its own indexing
    methods.

  • Concatenation returns an object of the subclass. If the subclass defines properties,
    then default concatenation no longer works and the subclass must define its own
    concatenation methods.


To list the built-in functions that work with a subclass of a built-in class, use the methods
function.

Built-In Subclasses That Define Properties


When a subclass of a built-in class defines properties, MATLAB no longer supports
indexing and concatenation operations. MATLAB cannot use the built-in functions
normally called for these operations because subclass properties can contain any data.

The subclass must define what indexing and concatenation mean for a class with
properties. If your subclass needs indexing and concatenation functionality, then the
subclass must implement the appropriate methods.

12 How to Build on Other Classes

Free download pdf