MATLAB Object-Oriented Programming

(Joyce) #1

Dynamic Properties — Adding Properties to an Instance


In this section...
“What Are Dynamic Properties” on page 8-69
“Define Dynamic Properties” on page 8-70

What Are Dynamic Properties


You can add properties to instances of classes that derive from the dynamicprops class.
These dynamic properties are sometimes referred to as instance properties. Use dynamic
properties to attach temporary data to objects or to assign data that you want to associate
with an instance of a class, but not all objects of that class.

It is possible for more than one program to define dynamic properties on the same object.
In these cases, avoid name conflicts. Dynamic property names must be valid MATLAB
identifiers (see “Variable Names”) and cannot be the same name as a method of the class.

Characteristics of Dynamic Properties

Once defined, dynamic properties behave much like class-defined properties:


  • Set and query the values of dynamic properties using dot notation. (See “Assign Data
    to the Dynamic Property” on page 8-71.)

  • MATLAB saves and loads dynamic properties when you save and load the objects to
    which they are attached. (See “Dynamic Properties and ConstructOnLoad” on page 8-
    80.)

  • Define attributes for dynamic property. (See “Set Dynamic Property Attributes” on
    page 8-70).

  • By default, dynamic properties have their NonCopyable attribute set to true. If you
    copy an object containing a dynamic property, the dynamic property is not copied.
    (See “Objects with Dynamic Properties” on page 7-41)

  • Add property set and get access methods. (See “Set and Get Methods for Dependent
    Properties” on page 8-62.)

  • Listen for dynamic property events. (See “Dynamic Property Events” on page 8-75.)

  • Access dynamic property values from object arrays, with restricted syntax. (See
    “Accessing Dynamic Properties in Arrays” on page 10-14.)


Dynamic Properties — Adding Properties to an Instance
Free download pdf