Sample 18 uses all object-oriented specific functions including encapsulation, inheritance and polymorphism.
This program, which deals with two or more employee objects, uses the Dict class created in Sample 16, “Collection Class (Class Library).”
Overview
The application shows how an OO system can be set up to manage employee information. It implements, in a basic manner, the functions of registering, deleting, and modifying employee details, calculating salaries and printing a directory of employee information.
The employees are classified into staff members and managers. Different data is maintained and the pay calculation method differs between staff members and managers. The elements of the application are:
An employee class that defines the attributes common to all employees (AllMember-class)
A staff member class that defines the attributes particular to staff employees (Member-Class)
A manager class that defines the attributes particular to managers (Manager-Class)
The staff member and manager classes inherit the employee class.
The addresses portion of the employee information is managed by an independent class (Address-Class).
Address objects are referenced from employee objects (and their subclasses).
The employee object defines the employee data to be managed by the supervisor.
Sample 18 use the dictionary class (Dict) created in Sample 16, “Collection Class (Class Library)”. It registers an employee object with the dictionary using the employee number as the key. The dictionary class allows easy repeat processing of two or more employee objects, and easy retrieval of an employee object.
Programs and Files in Sample 18
MAIN.COB (COBOL source program)
ALLMEM.COB (COBOL source program)
MEMBER.COB (COBOL source program)
MANAGER.COB (COBOL source program)
ADDRESS.COB (COBOL source program)
BONU_MAN.COB (COBOL source program)
BONU_MEM.COB (COBOL source program)
SALA_MAN.COB (COBOL source program)
SALA_MEM.COB (COBOL source program)
DICT.REP (Repository file)
SAMPLE18.PRJ (Project file)
SAMPLE18.CBI (Compiler option file)
COBOL85.CBR (Environment variable initialization file)
COLLECT.DLL (DLL file)
COLLECT.LIB (Import library)
COBOL Functions used in Sample 18
Object-oriented programming functions
Class definition (Encapsulation)
Inheritance
Object generation
Method calling
Polymorphism
Screen operation function
Project management
Object-Oriented Syntax used in Sample 18
INVOKE and SET statements
Object properties
In-line method calls
REPOSITORY paragraphs
Class, object and method definitions
Building the Application
Project Manager's build function is used to make the executable program.
Start the Project Manager.
Open project file SAMPLE18.PRJ.
Select Build from the Project menu.
Debugging the Application
The project file is supplied with the debugging option set. You can execute the program under the control of the COBOL Debugger by:
Selecting Debug from the Project menu.
Clicking on the OK button in the Start Debugging dialog box.
The COBOL Debugger loads the code as shown in the following figure.
Executing the Application
To run the application, select Execute from the Project menu.
The main application window is displayed:
To operate the program, enter the number of the desired process into “Select number” and press ENTER.
Note that this sample does not implement object persistence so data is lost when the application terminates. See Sample 19 for the same application with persistence added.
Registering Employee Information
Enter the employee information including:
Employee number (four-digit numeric character string);
Name (Character string of eight or fewer characters);
Address consisting of a (Japanese style) postal code (7 digits) and a character string of 20 or fewer characters
Date the employee joined the company (in the format of YY.MM.DD - for this program there is no date processing so the format is not significant)
Status code (1 for a manager, and 2 for a staff member); and
Basic pay (numeric character string of eight or fewer digits)
For a manager, type in the special allowances (numeric character string of six or fewer digits). For a general staff member, type in the overtime (numeric character string of five or fewer digits).
Press the F3 key to register the data.
To terminate processing of employee registration information, press the F2 key.
Deleting Employee Information
To delete employee information, type in the employee number (four-digit numeric character string), and press the F3 key.
The employee data is displayed and can be corrected.
Calculating Employee Pay
When you select the “Salary calculation” function, the pay of all employees is calculated.
Entering an employee number and pressing the F3 key displays the pay information for that employee.
To terminate processing of the salary calculation function, press the F2 key.
Address list
An employee address list can be printed. Select Manager (1) or General employee (2), and then press the F3 key.
End
Terminates processing.