Sample 17 demonstrates the general object-oriented design concepts of aggregation, singleton, and iteration.
The program use the Dict and List classes created in "Sample 16 Collection Class (Class Library)".
It also requires Microsoft Excel (abbreviated to “Excel”).
Overview
The purpose of Sample 17 is to illustrate implementation of the object-oriented concepts of aggregation, singleton and iteration (explained below). It uses a conference room booking system to demonstrate these features. The user interface is very basic as the focus is to demonstrate the OO concepts.
The conference room booking system provides functions for:
Reserving a conference room.
Canceling a conference booking.
Reviewing conference room bookings.
Listing, adding and deleting conference rooms.
Updating conference room details.
The OO concepts are demonstrated as described below.
Aggregation
Aggregation is a relation of "whole to part". The life of the downstream class instance in the aggregate relation is controlled completely by the life of the upstream class instance. In this sample, the following classes are in the aggregation relation:
Reservation-status-Date class (RSVSTATE-DATE-CLASS) and Reservation-status- Conference-Room class (RSVSTATE-CFNROOM-CLASS).
Reservation-status-Conference-Room class (RSVSTATE-CFNROOM-CLASS) and Reservation-status-Time-Frame class (RSVSTATE-TIME-CLASS).
Conference-Room-Information-Control calls (CFRINFO-CNT-CLASS) and Conference-Room-Information class (CFRINFO-CLASS).
Singleton
Singleton refers to a mechanism that guarantees that only one object instance can exist for a class.
This is implemented in the SINGLE-TON class in this sample. The SINGLE-TON class is inherited by the following classes so that they can only create a single object instance.
Reservation control class
RSVCNT-CLASS
Conference room information control class
CFRINFO-CNT-CLASS.
Error processing class
ERROR-CLASS
Iteration
Iteration provides a means of accessing elements sequentially without having to be aware of the internal structure of the aggregation object. In this sample, iteration is implemented by the LIST-ITERATER class.
Two or more LIST-ITERATER class objects can be created for a single list object.
In this sample, iteration is used in the following functions:
Display of reservation information
Method: RSV-SITUATION-LIST-DISP,
Class: RSVCNT-CLASS
Deletion of reservation state objects (date, conference room and time frame)
Method: RSV-SITUATION-OBJ-DEL
Class: RSVCNT-CLASS
Retrieval of conference room information and reservation information
Method: RSV-DATA-RETRIEVAL
Class: RSVINFO-CLASS
Storing the information in an Excel file.
Entry: PRESERVATION-DATA
Program: EXCEL-EDIT
Design of Sample 17
Following figure shows the relationships between the classes used in Sample 17.
Programs and Files in Sample 17
MAIN.COB (COBOL source program)
EXCELEDT.COB (COBOL source program)
RSVCTRL.COB (COBOL source program)
ROOMCTRL.COB (COBOL source program)
DATESTA.COB (COBOL source program)
ROOMSTA.COB (COBOL source program)
TIMESTA.COB (COBOL source program)
RESERVE.COB (COBOL source program)
SPECCTRL.COB (COBOL source program)
SPEC.COB (COBOL source program)
SINGLETN.COB (COBOL source program)
LISTITER.COB (COBOL source program)
ERRORPUT.COB (COBOL source program)
RSVINFO.CBL (library file)
ROOMINFO.CBL (library file)
R_CONST.CBL (library file)
SPECINFO.CBL (library file)
ROOMLIST.XLS (Excel file)
RSVLIST.XLS (Excel file)
DICT.REP (Repository file)
LIST.REP (Repository file)
SAMPLE17.PRJ (project file)
COLLECT.DLL (DLL file)
COLLECT.LIB (import library)
COBOL Functions used in Sample 17
Object oriented programming functions
Definition of class (encapsulation)
Inheritance
Multiple inheritance
Creation of objects
Method calls
Exception handling
OLE connection
Project manager function
Object-Oriented Syntax used in Sample 17
INVOKE and SET statements
Object properties
In-line method calls
REPOSITORY paragraphs
Class , object and method definitions
Type definitions
Before Executing the Application
Check the definitions of the Excel file names in the file:
R_CONST.CBL
used by most of the programs. (To edit this file expand the project tree down to a list of Copy Library Files for one of the programs, e.g. MAIN, and double click on the R_CONST.CBL file name.)
The names are defined at the head of the file as the constants: CNFROOM-FILENAME and RSV-FILE-NAME.
You may need to change the settings of these constants if you did not install to the default folder structure.
Sample17 frequently writes to the Excel files so if you want to preserve the original or other version of these files, please take a backup before running Sample17.
Attention
The code is written to discard out-of-date data. When objects are restored from the Excel file, any objects with dates earlier than the current date are discarded.
Likewise, when objects are preserved, any objects that are out-of-date are not written to the Excel file.
Building the Application
Project Manager's build function is used to make the executable program.
Start the Project Manager.
Open project file SAMPLE17.PRJ.
Select Build from the Project menu.
Executing the Application
To execute the program select Execute from the Project menu. (No run-time environment variables need to be set.)
When the program starts, it reloads the information from Excel, then displays a list of options:
Guidelines for Operating the Application
The application has a simple, menu-driven interface, controlled by the MAIN.COB program.
The main menu lets you select functions by entering a number from 1 to 3 or X to exit. The functions are:
Reserve and refer
this provides the ability to reserve conference rooms, see bookings of conference rooms (on a given date), and cancel bookings.
Retrieval
The retrieval function returns all conference room bookings for a given name.
Conference room control
The conference room control function lets you update, add and delete conference room details.
Once you have entered the primary function you are prompted to enter data an item at a time. Sometimes the interface introduces a set of information to be entered, such as "Enter the conference room name, and time at which it should be booked" and the prompts for the first piece of information (the conference room name). Just enter the first piece of information and you will be prompted for the other pieces in the set.
You'll be asked for the following information for the different functions:
Reserve and refer
An 8-digit date (equal to or later than today's date)
Conference room name (4 characters)
Time (AM or PM)
If there is no booking for that room, date and time, you are prompted for:
Name (10 characters)
Extension (9 digits)
Department (10 characters)
and are returned a reservation number (required if you later want to cancel the reservation).
If there is a booking for the room, the booking details are displayed and you have the option to cancel the room. If you choose to cancel the booking you are prompted for the 4 digit reservation number.
Retrieval
You are prompted to enter:
Subscriber name (10 digits) - the name entered when booking the room.
Information corresponding to the name is displayed.
NOTE: The program is configured so that it only displays five reservations. To increase this change the following item in the R_CONST.CBL file.
RSV-MAX IS 5
Conference room control
You are prompted to enter:
Conference room name (4 characters)
If the conference room exists, details for that conference room are listed. If it doesn't exist you are prompted to enter details to register the conference room. The conference room details are:
Capacity (2 digits)
Extension (9 digits)
Type (N for general, T for video)
When changes are completed the appropriate updates are made to the Excel file to reflect the changes.
End
The program saves reservation information objects in the Excel file and terminates.