Example of Class Definition Syntax
April 20th, 2010 Posted in Examples
Example of Class Definition 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 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 |
Leave a Reply
You must be logged in to post a comment.