MATLAB Object-Oriented Programming

(Joyce) #1
classdef ClassName
properties (PropertyAttribute = value)
Prop1
Prop2
end
end

For example, only methods in the same class definition can modify and query the Salary
and Password properties.

classdef EmployeeInfo
properties (Access = private)
Salary
Password
end
end

This restriction exists because the class defines these properties in a properties block
with the Access attribute set to private.

Property Attributes

For a description of property attributes you can specify, see, “Property Attributes” on
page 8-9.

Property Access Methods


MATLAB calls whenever setting or querying a property value. Define property set access
or get access methods in methods blocks that specify no attributes and have the
following syntax:

methods

function obj = set.PropertyName(obj,value)
...
end

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

end

MATLAB does not call the property set access method when assigning the default value
specified in the property's definition block.

8 Properties — Storing Class Data

Free download pdf