MATLAB Object-Oriented Programming

(Joyce) #1
(from [1 0 0] to [.93 .14 .14], for example) without updating every function that
accepts colors, as you would if you defined the color as the char vector 'red'.

Define enumerations by creating an enumeration block in the class definition.


See “Define Enumeration Classes” on page 14-5 for more information.


Techniques for Defining Enumerations


Enumerations enable you to define names that represent entities useful to your
application, without using numeric values or character strings. All enumerations support
equality and inequality operations. Therefore, switch, if, and several comparison
functions like isequal and ismember work with enumeration members.


You can define enumeration classes in ways that are most useful to your application, as
described in the following sections.


Simple Enumerated Names


Simple enumeration classes have no superclasses and no properties. These classes define
a set of related names that have no underlying values associated with them. Use this kind
of enumeration when you want descriptive names, but your application does not require
specific information associated with the name.


See the WeekDays class in the “Enumeration Class” on page 14-5 and the “Define
Methods in Enumeration Classes” on page 14-7 sections.


Enumerations with Built-In Class Behaviors


Enumeration classes that subclass MATLAB built-in classes inherit most of the behaviors
of those classes. For example, an enumeration class derived from the double class
inherits the mathematical, relational, and set operations that work with variables of the
class.


Enumerations do not support the colon (:) operator, even if the superclass does.


Enumerations with Properties for Member Data


Enumeration classes that do not subclass MATLAB built-in numeric and logical classes
can define properties. These classes can define constructors that set each member's
unique property values.


Named Values
Free download pdf