A Class Code Listing
An Example of Syntax
The following code shows the syntax of a typical class definition.
This example is not a functioning class because it references functions
that it does not implement. The purpose of this section is to illustrate
various syntactic constructions.
classdef (ConstructOnLoad) employee < handle
% Class help goes here
properties
Name % Property help goes here
end
properties (Dependent)
JobTitle
end
properties (Transient)
OfficeNumber
end
properties (SetAccess = protected, GetAccess = private)
EmpNumber
end
events
BackgroundAlert
end
methods
function Eobj = employee(name)
% Method help here
Eobj.Name = name;
Eobj.EmpNumber = employee.getEmpNumber;
end
function result = backgroundCheck(obj)
result = queryGovDB(obj.Name,obj.SSNumber);
if result == false
notify(obj,'BackgroundAlert');
end
end
function jobt = get.JobTitle(obj)
jobt = currentJT(obj.EmpNumber);
end
function set.OfficeNumber(obj,setvalue)
if isInUse(setvalue)
error('Not available')
else
obj.OfficeNumber = setvalue;
end
end
end
methods (Static)
function num = getEmpNumber
num = queryDB('LastEmpNumber') + 1;
end
end
end
Back to Top
 | Specifying Attributes | | Understanding M-Lint Syntax Warnings |  |
Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
Get the Interactive Kit