Hierarchical structure of code:
+foddername This is the package name and defines a namespace for its internal content
@classname This is the class folder, and the folder name is the class name
CLASSNAME.M this file as the primary class
FUNCTIONNAME.M this file as a class function file
You can place the keynote function on the outermost layer, which is parallel to the package name.
Main class Code structure
ClassDef (constructonload=true,sealed) myclock
in the command window enter t= myclock (8,30,20) Run program
%constructonload=true, The constructor of the object is called when the class is loaded.
Properties
Hour; % when
Minute; %
Second; % sec
End
methods
function Obj=myclock (h,m,s) % constructor
obj. Hour=h;
Obj. minute=m;
Obj. Second=s;
End
function Show (obj)
disp [Num2str (obj. Hour), ': ',...
Num2str (obj. Minute, ': ', num2str (obj. Second)]);
End
Function value = Get. Hour (object)
value = obj. Hour;
Disp (' Querying Hour value ')
end
Function obj = set. Hour (Obj,value)
if~ (value>0)
error (' property value must is positive ')
else
obj. Hour = value;
End
disp (' Setting Hour value! ')
End
End
Properties define Variables
The
methods defines a method in which the same function as the class name is a constructor.