MATLAB Object-Oriented Programming

(Joyce) #1

  • The isequal function always returns false when comparing objects that have
    dynamic properties, even if the properties have the same name and value. To compare
    objects that contain dynamic properties, overload isequal for your class.


Define Dynamic Properties


Any class that is a subclass of the dynamicprops class (which is itself a subclass of the
handle class) can define dynamic properties using the addprop method. The syntax is:

P = addprop(H,'PropertyName')

where:

P is an array of meta.DynamicProperty objects

H is an array of handles

PropertyName is the name of the dynamic property you are adding to each object

Name Dynamic Properties

Use only valid names when naming dynamic properties (see “Variable Names”). In
addition, do not use names that:


  • Are the same as the name of a class method

  • Are the same as the name of a class event

  • Contain a period (.)


Set Dynamic Property Attributes

To set property attributes, use the meta.DynamicProperty object associated with the
dynamic property. For example, if P is the object returned by addprop, this statement
sets the property’s Hidden attribute to true:

P.Hidden = true;

The property attributes Constant and Abstract have no meaning for dynamic
properties. Setting the value of these attributes to true has no effect.

Remove a Dynamic Property

Remove the dynamic property by deleting its meta.DynamicProperty object:

8 Properties — Storing Class Data

Free download pdf