MATLAB Object-Oriented Programming

(Joyce) #1

See “Specifying Attributes” on page 6-8 for more on attribute syntax.


Kinds of Classes


There are two kinds of MATLAB classes—handle classes and value classes.



  • Value classes represent independent values. Value objects contain the object data and
    do not share this data with copies of the object. MATLAB numeric types are value
    classes. Values objects passed to and modified by functions must return a modified
    object to the caller.

  • Handle classes create objects that reference the object data. Copies of the instance
    variable refer to the same object. Handle objects passed to and modified by functions
    affect the object in the caller’s workspace without returning the object.


For more information, see “Comparison of Handle and Value Classes” on page 7-2.


Constructing Objects


For information on class constructors, see “Class Constructor Methods” on page 9-21.


For information on creating arrays of objects, see “Construct Object Arrays” on page 10-
2.


Class Hierarchies


For more information on how to define class hierarchies, see “Hierarchies of Classes —
Concepts” on page 12-2.


classdef Syntax


Class definitions are blocks of code that are delineated by the classdef keyword at the
beginning and the end keyword at the end. Files can contain only one class definition.


The following diagram shows the syntax of a classdef block. Only comments and blank
lines can precede the classdef keyword.


User-Defined Classes
Free download pdf