MATLAB Object-Oriented Programming

(Joyce) #1
end
function getPrePropEvt(obj,src,evnt)
disp ('Pre-get event triggered')
% ...
end
function setPrePropEvt(obj,src,evnt)
disp ('Pre-set event triggered')
% ...
end
function getPostPropEvt(obj,src,evnt)
disp ('Post-get event triggered')
% ...
end
function setPostPropEvt(obj,src,evnt)
disp ('Post-set event triggered')
% ...
end
function disp(obj)
% Overload disp to avoid accessing property
disp (class(obj))
end
end
end

The class specifies an initial value of 7 for the PropOne property. Therefore, if you create
an object and assign the property value of 7 , there is no need to trigger the PreSet
event. However, the getPropOne method is called to get the current value of the
property to compare to the assigned vale.

obj = AbortTheSet;
obj.PropOne = 7;

get.PropOne called

If you specify a value other than 7 , then MATLAB performs these steps:


  • Gets the current property value

  • Triggers the PreSet event

  • Sets the property to the assigned value

  • Triggers the PostSet event


obj = AbortTheSet;
obj.PropOne = 9;

11 Events — Sending and Responding to Messages

Free download pdf