MATLAB Object-Oriented Programming

(Joyce) #1

Types of Properties


There are two types of properties:



  • Stored properties — Use memory and are part of the object

  • Dependent properties — No allocated memory and the get access method calculates
    the value when queried


Features of Stored Properties



  • Can assign an initial value in the class definition

  • Property value is stored when you save the object to a MAT-file

  • Can use a set access method to control possible values, but you are not required to use
    such methods.


When to Use Stored Properties



  • You want to be able to save the property value in a MAT-file

  • The property value is not dependent on other property values


Features of Dependent Properties


Dependent properties save memory because property values that depend on other values
are calculated only when needed.


When to Use Dependent Properties


Define properties as dependent when you want to:



  • Compute the value of a property from other values (for example, you can compute
    area from Width and Height properties).

  • Provide a value in different formats depending on other values. For example, the size
    of a push button in values determined by the current setting of its Units property.

  • Provide a standard interface where a particular property is or is not used, depending
    on other values. For example, different computer platforms can have different
    components on a toolbar).


For examples of classes that use dependent properties, see “Calculate Data on Demand”
on page 3-23 and “A Class Hierarchy for Heterogeneous Arrays” on page 20-2.


Ways to Use Properties
Free download pdf