MATLAB Object-Oriented Programming

(Joyce) #1

Properties Containing Objects


In this section...
“Assigning Objects as Default Property Values” on page 8-66
“Assigning to Read-Only Properties Containing Objects” on page 8-66
“Assignment Behavior” on page 8-66

Assigning Objects as Default Property Values


MATLAB evaluates property default values only once when loading the class. MATLAB
does not reevaluate the assignment each time you create an object of that class. If you
assign an object as a default property value in the class definition, MATLAB calls the
constructor for that object only once when loading the class.

NoteEvaluation of property default values occurs only when the value is first needed,
and only once when MATLAB first initializes the class. MATLAB does not reevaluate the
expression each time you create an instance of the class.

For more information on the evaluation of expressions that you assign as property default
values, see “When MATLAB Evaluates Expressions” on page 6-13.

Assigning to Read-Only Properties Containing Objects


When a class defines a property with private or protected SetAccess, and that property
contains an object which itself has properties, assignment behavior depends on whether
the property contains a handle or a value object:


  • Handle object – you can set properties on handle objects contained in read-only
    properties

  • Value object – you cannot set properties on value object contained in read-only
    properties.


Assignment Behavior


These classes illustrate the assignment behavior:

8 Properties — Storing Class Data

Free download pdf