19.12 Example Outline--Personnel Records

One of the things computers spend most of their time doing is keeping track of various types of business records. These come in a wide variety of different forms, but often have many elements in common. For instance, in a university environment, every member of the community comes attached to such information as their name, birthdate, address, and sex. Students major or minor in a discipline, take courses, and generate a variety of other data exclusive to them. Others are employees, with certain data common to all of them, but falling into the two broad categories of staff and faculty, each with data not shared by the others. A sketch of a partial design for the data structures is shown in figure 19.3.

The base class for personnel data does not inherit from such classes as address, but it does make use of them in its own structures. When doing so, a class has to create the instances it needs of any other classes when it initializes. If the class were unsafeguarded, it should dispose of the subsidiary objects in its destructor. What follows is an outline of some of the code. It is far from complete, (no methods have been included), and is intended to show only some of the relationships among the classes and types of data needed. In addition, the class CommonInfo illustrates the correct positioning of an exception handler for a class body.

MODULE URecords;

(* a rough sketch of some University record keeping classes
  to demonstrate class design 
  by R. Sutcliffe 1998 10 05 *)
  
FROM Dates IMPORT Date;

TRACED CLASS Address;
  REVEAL SetAddress, WriteAddress;
  VAR
    street1, street2, town, country : ARRAY [0..20] OF CHAR;
    code : ARRAY [0..10] OF CHAR;
  PROCEDURE SetAddress;
  (* code to do so *)
  END SetAddress;

  PROCEDURE WriteAddress;
  (* code to do so *)
  END WriteAddress;

  END Address;
  
(* the base information class common to everybody *)
TRACED CLASS CommonInfo;
  REVEAL birthDate, adr, sin, sex;
  VAR
    birthDate : Date;
    adr : Address;
    sin : CARDINAL;
    sex : BOOLEAN;
    (* methods *)
  BEGIN
    CREATE (birthDate);
    CREATE (adr);
    (* if untraced, these have to be destroyed in finally clause *)
  EXCEPT
  (* exception handling goes here if necessary *)
  END CommonInfo;

(* the base class for all employees *)
TRACED CLASS Employee;
  INHERIT CommonInfo;
  REVEAL department; (* and whatever *)
  VAR
    department : ARRAY [0..20] OF CHAR;
    startDate : Date;
    salary : REAL;
    bankName : ARRAY [0..15] OF CHAR;
    fullTime : BOOLEAN;
    (* methods *)
  BEGIN
    CREATE (startDate);
    (* if untraced, has to be destroyed in finally clause *)
  END Employee;
  
(* specialized employee classes *)
TRACED CLASS FacultyMember;
  INHERIT Employee;
  REVEAL rank; (* and whatever *)
  VAR
    rank, faculty : ARRAY [0..20] OF CHAR;
    (* methods *)
  END FacultyMember;

TRACED CLASS StaffMember;
  INHERIT Employee;
  REVEAL jobTitle; (* and whatever *)
  VAR
    jobTitle : ARRAY [0..20] OF CHAR;
    supervisor : StaffMember;
    (* methods *)
  END StaffMember;

(* data types for courses and schedules *)
TYPE
  DayAbbrev = (M, T, W, R, F, S); (* no sunday classes *)
  DaySet = SET OF DayAbbrev;
  
TRACED CLASS Course;
  VAR
    dept : ARRAY [0..3] OF CHAR;
    courseNum : [1..999];
    credits : [0..3]; (* needs a fix if half credits allowed *)
    startDate, endDate : Date;
    daysOffered : DaySet;
    (* need times too *)
    
  BEGIN    
    CREATE (startDate);
    CREATE (endDate);

  END Course;

TRACED CLASS Schedule;
  VAR
    indivSchedule : ARRAY [0..10] OF Course;
  (* methods *)
  END Schedule;

TRACED CLASS Student;
  INHERIT CommonInfo;
  REVEAL major; (* and more *)
  VAR
    major : ARRAY [0..20] OF CHAR;
    year : (freshman, sophomore, junior, senior);
    sched : Schedule;
    (* info and methods *)
  
  END Student;

END URecords.

Contents