MATLAB Object-Oriented Programming

(Joyce) #1
events
UpdateGraph
end

Determine When to Trigger Event

The fcneval class defines a property set method for the FofXY property. FofXY is the
property that stores the MATLAB expression for the mathematical function. This
expression must be a valid MATLAB expression for a function of two variables.

The set.FofXY method:


  • Determines the suitability of the expression

  • If the expression is suitable:

    • Assigns the expression to the FofXY property

    • Triggers the UpdateGraph event




If fcneval.isSuitable does not return an MException object, the set.FofXY
method assigns the value to the property and triggers the UpdateGraph event.

function set.FofXY(obj,func)
% Determine if function is suitable to create a surface
me = fcneval.isSuitable(func);
if ~isempty(me)
throw(me)
end
% Assign property value
obj.FofXY = func;
% Trigger UpdateGraph event
notify(obj,'UpdateGraph');
end

Determine Suitability of Expression

The set.FofXY method calls a static method (fcneval.isSuitable) to determine the
suitability of the specified expression. fcneval.isSuitable returns an MException
object if it determines that the expression is unsuitable. fcneval.isSuitable calls the
MException constructor directly to create more useful error messages for the user.

set.FofXY issues the exception using the MException.throw method. Issuing the
exception terminates execution of set.FofXY and prevents the method from making an
assignment to the property or triggering the UpdateGraph event.

11 Events — Sending and Responding to Messages

Free download pdf