Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.18 Sample 17: Object-Oriented Cobol (Aggregation, Singleton, and Iteration)

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:

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:

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.

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:

Design of Sample 17

Following figure shows the relationships between the classes used in Sample 17.

Programs and Files in Sample 17

COBOL Functions used in Sample 17

Object-Oriented Syntax used in Sample 17

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.

  1. Start the Project Manager.

  2. Open project file SAMPLE17.PRJ.

  3. 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:

  1. Reserve and refer

    this provides the ability to reserve conference rooms, see bookings of conference rooms (on a given date), and cancel bookings.

  2. Retrieval

    The retrieval function returns all conference room bookings for a given name.

  3. 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.