MATLAB Object-Oriented Programming

(Joyce) #1

classdef SquareArea
properties
Width
Height
end
properties (Dependent)
Area
end
methods
function a = get.Area(obj)
a = obj.Width * obj.Height;
end
end
end


Errors Not Returned from Get Method


The MATLAB default object display suppresses error messages returned from property
get methods. MATLAB does not allow an error issued by a property get method to prevent
the display of the entire object.


Use the property set method to validate the property value. Validating the value when
setting a property ensures that the object is in a valid state. Use the property get method
only to return the value that the set method has validated.


Get Method Behavior


MATLAB does NOT call property get methods in the following cases:



  • Getting a property value from within its own property get method, which prevents
    recursive calling of the get method

  • Copying a value object (that is, not derived from the handle class). Neither the set or
    get method is called when copying property values from one object to another.


See Also


Related Examples



  • “Set and Get Methods for Dependent Properties” on page 8-62


See Also
Free download pdf