Representative Class Code

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.

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
Was this topic helpful?