MATLAB Object-Oriented Programming

(Joyce) #1

  • Property PropOne PostSet event

  • Property PropTwo PostSet event


You can define listeners for other events or other properties using a similar approach. It is
not necessary to use the same callback function for each listener. See the
meta.property and event.PropertyEvent reference pages for more on the
information contained in the arguments passed to the listener callback function.


classdef PropListener < handle
% Define property listeners
methods
function obj = PropListener(evtobj)
if nargin > 0
addlistener(evtobj,'PropOne','PostSet',@PropListener.handlePropEvents);
addlistener(evtobj,'PropTwo','PostSet',@PropListener.handlePropEvents);
end
end
end
methods (Static)
function handlePropEvents(src,evnt)
switch src.Name
case 'PropOne'
sprintf('PropOne is %s\n',num2str(evnt.AffectedObject.PropOne))
case 'PropTwo'
sprintf('PropTwo is %s\n',num2str(evnt.AffectedObject.PropTwo))
end
end
end
end


See Also


Related Examples



  • “Assignment When Property Value Is Unchanged” on page 11-44


See Also
Free download pdf