MATLAB Object-Oriented Programming

(Joyce) #1

Mutable Handle vs. Immutable Value Enumeration


Members


In this section...
“Select Handle- or Value-Based Enumerations” on page 14-34
“Value-Based Enumeration Classes” on page 14-34
“Handle-Based Enumeration Classes” on page 14-36
“Represent State with Enumerations” on page 14-39

Select Handle- or Value-Based Enumerations


Use a handle enumeration to enumerate a set of objects whose state can change over
time. Use a value enumeration to enumerate a set of abstract (and immutable) values. For
information about handle and value classes, see “Comparison of Handle and Value
Classes” on page 7-2.

Value-Based Enumeration Classes


A value-based enumeration class has a fixed set of specific values. Modify these values by
changing the values of properties. Doing so expands or changes the fixed set of values for
this enumeration class.

Inherited Property SetAccess Must Be Immutable

Value-based enumeration classes implicitly define the SetAccess attributes of all
properties as immutable. You cannot set the SetAccess attribute to any other value.

However, all superclass properties must explicitly define property SetAccess as
immutable.

Enumeration Members Remain Constant

An instance of a value-based enumeration class is unique until the class is cleared and
reloaded. For example, given this class:

classdef WeekDays
enumeration
Monday, Tuesday, Wednesday, Thursday, Friday

14 Enumerations

Free download pdf