MATLAB Object-Oriented Programming

(Joyce) #1

Property Get Methods


In this section...
“Overview of Property Access Methods” on page 8-60
“Property Get Method Syntax” on page 8-60
“Calculate Value for Dependent Property” on page 8-60
“Errors Not Returned from Get Method” on page 8-61
“Get Method Behavior” on page 8-61

Overview of Property Access Methods


For an overview of property access methods, see “Property Access Methods” on page 8-
50.

Property Get Method Syntax


MATLAB calls a property's get method whenever the property value is queried.

NoteYou cannot call property access methods directly. MATLAB calls these
methods when you access property values.

Property get methods have the following syntax, where PropertyName is the name of the
property. The function must return the property value.

methods
function value = get.PropertyName(obj)
...
end

Calculate Value for Dependent Property


The SquareArea class defines a dependent property Area. MATLAB does not store a
value for the dependent Area property. When you query the value of the Area property,
MATLAB calls the get.Area method calculates the value based on the Width and
Height properties.

8 Properties — Storing Class Data

Free download pdf