MATLAB Object-Oriented Programming

(Joyce) #1

Kinds of Methods


There are specialized kinds of methods that perform certain functions or behave in
particular ways:



  • Ordinary methods are functions that act on one or more objects and return some new
    object or some computed value. These methods are like ordinary MATLAB functions
    that cannot modify input arguments. Ordinary methods enable classes to implement
    arithmetic operators and computational functions. These methods require an object of
    the class on which to operate. See “Ordinary Methods” on page 9-8.

  • Constructor methods are specialized methods that create objects of the class. A
    constructor method must have the same name as the class and typically initializes
    property values with data obtained from input arguments. The class constructor
    method must declare at least one output argument, which is the object being
    constructed. The first output is always the object being constructed. See “Class
    Constructor Methods” on page 9-21

  • Destructor methods are called automatically when the object is destroyed, for example
    if you call delete(object) or there are no longer any references to the object. See
    “Handle Class Destructor” on page 7-16

  • Property access methods enable a class to define code to execute whenever a property
    value is queried or set. See “Property Access Methods” on page 8-50

  • Static methods are functions that are associated with a class, but do not necessarily
    operate on class objects. These methods do not require an instance of the class to be
    referenced during invocation of the method, but typically perform operations in a way
    specific to the class. See “Static Methods” on page 9-32

  • Conversion methods are overloaded constructor methods from other classes that
    enable your class to convert its own objects to the class of the overloaded constructor.
    For example, if your class implements a double method, then this method is called
    instead of the double class constructor to convert your class object to a MATLAB
    double object. See “Object Converters” on page 17-12 for more information.

  • Abstract methods define a class that cannot be instantiated itself, but serves as a way
    to define a common interface used by numerous subclasses. Classes that contain
    abstract methods are often referred to as interfaces. See “Abstract Classes” on page
    12-91 for more information and examples.


Methods in Class Design
Free download pdf