MATLAB Object-Oriented Programming

(Joyce) #1

  • For concrete properties (that is, properties that are not abstract)

  • Within the class that defines the property (unless the property is abstract in that class,
    in which case the concrete subclass must define the access method).


MATLAB has no default set or get property access methods. Therefore, if you do not
define property access methods, MATLAB software does not invoke any methods before
assigning or returning property values.

Once defined, only the set and get methods can set and query the actual property values.
See “When Set Method Is Called” on page 8-57 for information on cases where MATLAB
does not call property set methods.

NoteProperty set and get access methods are not equivalent to user-callable set and
get methods used to set and query property values from an instance of the class. See
“Implement Set/Get Interface for Properties” on page 7-28 for information on user-
callable set and get methods.

Access Methods Cannot Call Functions to Access Properties

You can set and get property values only from within your property set or get access
method. You cannot call another function from the set or get method and attempt to
access the property value from that function.

For example, an anonymous function that calls another function to do the actual work
cannot access the property value. Similarly, an access function cannot call another
function to access the property value.

Defining Access Methods

Access methods have special names that include the property name. Therefore,
get.PropertyName executes whenever PropertyName is referenced and
set.PropertyName executes whenever PropertyName is assigned a value.

Define property access methods in a methods block that specifies no attributes. You
cannot call these methods directly. MATLAB calls these methods when any code accesses
the properties.

Property access methods do not appear in the list of class methods returned by the
methods command and are not included in the meta.class object Methods property.

8 Properties — Storing Class Data

Free download pdf