MATLAB Object-Oriented Programming

(Joyce) #1

Implement Set/Get Interface for Properties


In this section...
“The Standard Set/Get Interface” on page 7-28
“Subclass Syntax” on page 7-28
“Get Method Syntax” on page 7-29
“Set Method Syntax” on page 7-29
“Class Derived from matlab.mixin.SetGet” on page 7-30

The Standard Set/Get Interface


Some MATLAB objects, such as graphics objects, implement an interface based on set
and get functions. These functions enable access to multiple properties on arrays of
objects in a single function call.

You can add set and get functionality to your class by deriving from one of these classes:


  • matlab.mixin.SetGet — use when you want support for case-insensitive, partial
    property name matching. Deriving from matlab.mixin.SetGet does not affect the
    exact property name required by the use of dot notation reference to properties.

  • matlab.mixin.SetGetExactNames — use when you want to support only case-
    sensitive full property name matching.


NoteThe set and get methods referred to in this section are different from property set
access and property get access methods. See “Property Access Methods” on page 8-50
for information on property access methods.

Subclass Syntax


Use the abstract class matlab.mixin.SetGet or matlab.mixin.SetGetExactNames
as a superclass:

classdef MyClass < matlab.mixin.SetGet
...
end

7 Value or Handle Class — Which to Use

Free download pdf