MATLAB Object-Oriented Programming

(Joyce) #1

Object arrays in MATLAB are homogeneous in class. Because of this homogeneity, you can
perform operations on whole arrays, such as multiplying numeric matrices. You can form
heterogeneous array by defining a hierarchy of classes that derive from a common
superclass. Cell arrays provide option for an array type that can hold different kinds of
unrelated objects.


Heterogeneous Hierarchies


You can form arrays of objects that are subclasses of a common superclass when these
classes are part of a heterogeneous hierarchy. A MATLAB heterogeneous class hierarchy:



  • Derives from matlab.mixin.Heterogeneous

  • Defines a single root superclass that derives directly from
    matlab.mixin.Heterogeneous

  • Seals methods that are inherited by subclasses.


For example, in the following diagram, Shape is the root of the heterogeneous hierarchy.


Heterogeneous Arrays


A heterogeneous array is an array of objects that differ in their specific class, but all
objects derive from or are instances of a common superclass. The common superclass
forms the root of the hierarchy of classes that you can combine into heterogeneous
arrays.


The common superclass class must derive from matlab.mixin.Heterogeneous.
Methods that you can call on the array as a whole must have the same definitions for all
subclasses.


Designing Heterogeneous Class Hierarchies............ 10-

Free download pdf