MATLAB Object-Oriented Programming

(Joyce) #1

Property Access Methods


In this section...
“Properties Provide Access to Class Data” on page 8-50
“Property Setter and Getter Methods” on page 8-51
“Set and Get Method Execution and Property Events” on page 8-53
“Access Methods and Properties Containing Arrays” on page 8-54
“Access Methods and Arrays of Objects” on page 8-54
“Modify Property Values with Access Methods” on page 8-54

Properties Provide Access to Class Data


In MATLAB, properties can have public access. Therefore, properties can provide access
to data that the class design exposes to users.

Use property access methods to provide error checking or to implement side effects
resulting from property access. Examples of access methods include functions that update
other property values when setting the property or translate the format of a property
value before returning the value.

You can use property validation to restrict the size, class, and other aspects of property
values. For information on property validation, see “Validate Property Values” on page 8-
24.

Performance Considerations with Access Methods

Property access methods do add the overhead of a function call whenever accessing
property values. If performance-critical access to properties occurs inside methods of the
class, define private properties to store values. Use these values inside methods without
any error checking. For less frequent access from outside the class, define public
Dependent properties that use access methods for error checking.

For information on access methods used with Dependent properties, see “Set and Get
Methods for Dependent Properties” on page 8-62.

8 Properties — Storing Class Data

Free download pdf