MATLAB Object-Oriented Programming

(Joyce) #1

A Complete Class


A complete class definition contains any combination of properties, methods, and events
code blocks.

classdef (Sealed) MyClass < handle
properties (SetAccess = private)
Prop1 = datenum(date)
end
properties
Prop2
end
methods
function obj = MyClass(x)
obj.Prop2 = x;
end
end
methods (Access = {?MyOtherClass})
function d = myMethod(obj)
d = obj.Prop1 + x;
end
end
events (ListenAccess = protected)
StateChanged
end
end

Enumeration Classes


Enumeration classes are specialized classes that define a fixed set of names representing
a single type of value. Enumeration classes use an enumeration block that contains the
enumeration members defined by the class.

The enumeration block starts with the enumeration keyword and terminates with the
end keyword.

classdef ClassName < SuperClass
enumeration
EnumerationMember
end
...
end

5 Class Definition—Syntax Reference

Free download pdf