MATLAB Object-Oriented Programming

(Joyce) #1

Access Method Function Handles


The property meta.property object contains function handles to the property set and
get methods. SetMethod contains a function handle to the set method. GetMethod
contains a function handle to the get method.


Obtain these handles from the meta.property object:


mc = ?ClassName;
mp = findobj(mc.PropertyList,'Name','PropertyName');
fh = mp.GetMethod;


For example, if the class MyClass defines a get method for its Text property, you can
obtain a function handle to this function from the meta.class object:


mc = ?MyClass;
mp = findobj(mc.PropertyList,'Name','Text');
fh = mp.GetMethod;


The returned value, fh, contains a function handle to the get method defined for the
specified property name for the specified class.


For information on defining function handles, see “Create Function Handle”


Set and Get Method Execution and Property Events


MATLAB software generates events before and after set and get operations. You can use
these events to inform listeners that property values have been referenced or assigned.
The timing of event generation is as follows:



  • PreGet — Triggered before calling the property get method

  • PostGet — Triggered after the property get method has returned its value


If a class computes a property value (Dependent = true), then the behaviors of its set
events are like the get events:



  • PreSet — Triggered before calling the property set method

  • PostSet — Triggered after calling the property set method


If a property is not computed (Dependent = false, the default), then the assignment
statement with the set method generates the events:


Property Access Methods
Free download pdf