MATLAB Object-Oriented Programming

(Joyce) #1

  • Using no input arguments, if the enumeration member defines no input arguments

  • Using the input arguments defined in the enumeration class for that member


For example, the input arguments for the Bool class are 0 for Bool.No and 1 for
Bool.Yes.


classdef Bool < logical
enumeration
No (0)
Yes (1)
end
end


The values of 0 and 1 are of class logical because the default constructor passes the
argument to the first superclass. That is, this statement:


n = Bool.No;


Results in a call to logical that is equivalent to the following statement in a constructor:


function obj = Bool(val)
obj@logical(val)
end


MATLAB passes the member argument only to the first superclass. For example, suppose
Bool derived from another class:


classdef Bool < logical & MyBool
enumeration
No (0)
Yes (1)
end
end


The MyBool class can add some specialized behavior:


classdef MyBool
methods
function boolValues = testBools(obj)
...
end
end
end


The default Bool constructor behaves as if defined like this function:


Define Enumeration Classes
Free download pdf