MATLAB Object-Oriented Programming

(Joyce) #1

Why Subclass Built-In Types


Subclass a built-in class to extend the operations that you can perform on a particular
class of data. For example , when you want to:



  • To perform unique operations on class data.

  • Be able to use methods of the built-in class and other built-in functions directly with
    objects of the subclass. For example, you do not need to reimplement all the
    mathematical operators if you derived from a class such as double that defines these
    operators.


Which Functions Work with Subclasses of Built-In Types


Consider a class that defines enumerations. It can derive from an integer class and inherit
methods that enable you to compare and sort values. For example, integer classes like
int32 support all the relational methods (eq, ge, gt, le, lt, ne).


To see a list of functions that the subclass has inherited as methods, use the methods
function:


methods('SubclassName')


Generally, you can use an object of the subclass with any:



  • Inherited methods

  • Functions that normally accept input arguments of the same class as the superclass.


Behavior of Built-In Functions with Subclass Objects


When you define a subclass of a built-in class, the subclass inherits all the methods
defined by that built-in class. MATLAB also provides additional methods to subclasses of
built-in classes that override several built-in functions.


Built-in functions and methods that work on built-in classes can behave differently when
called with subclasses of built-in classes. Their behavior depends on which function you
are using and whether your subclass defines properties.


Subclasses of MATLAB Built-In Types
Free download pdf