MATLAB Object-Oriented Programming

(Joyce) #1

Property Setter and Getter Methods


Property access methods execute specific code whenever the property value is queried or
assigned a value. These methods enable you to perform various operations:



  • Execute code before assigning property values to perform actions such as:

    • Impose value range restrictions (“Validate Property Values” on page 8-24)

    • Check for proper types and dimensions

    • Provide error handling



  • Execute code before returning the current values of properties to perform actions
    such as:

    • Calculate the value of properties that do not store values (see “Calculate Data on
      Demand” on page 3-23)

    • Change the value of other properties

    • Trigger events (see “Overview Events and Listeners” on page 11-2)




To control what code can access properties, see “Property Attributes” on page 8-9.


MATLAB Calls Access Methods


NoteYou cannot call property access methods directly. MATLAB calls these
methods when you access property values.


Property access methods execute automatically whenever you set or query the
corresponding property values from outside the access method. MATLAB does not call
access methods recursively. That is, MATLAB does not call the set method when setting
the property from within its set method. Similarly, MATLAB does not call the get method
when querying the property value from within its get method.


Obtain the function handle for the set and get access methods from the property
meta.property object. The meta.property SetMethod and GetMethod properties
contain the function handles that refer to these methods.


Restrictions on Access Methods


Define property access methods only:


Property Access Methods 8-

Free download pdf