Top
NetCOBOL V11.0 Getting Started
FUJITSU Software

A.16 Sample 15: Basic Object-Oriented Programming

This program illustrates basic object-oriented programming functions including encapsulation, object generation and method invocation.

Overview

In the sample program, three employee objects are generated. After an object has been generated using the "NEW" method, the "Data-Set" method is invoked to set the data.

Although all the employee objects have the same form, they have different data (employee numbers, names, departments and sections, and address information). Address information also belongs to an object, containing postal codes and addresses.

Upon input of an employee number on the screen, the appropriate "Data-Display" method in the employee object is invoked, with employee information in the object is displayed on the screen.

The employee object invokes the "Data-Get" method of the associated address object to acquire the address information.

The employee object consists of three pieces of data and an object reference to an address object. The structure of the object is transparent to the main program user. The user must, however, understand the two methods of "Data-Set" and "Data-Display."

The encapsulation of data completely masks the information in the object.

Files Included in Sample 15

COBOL Functions used in Sample 15

Object-Oriented Syntax used in Sample 15

Building/Rebuilding the Program

Project manager's build function is used to create the executable program.

In the following screen snapshots, the sample program was installed to C:\NetCOBOL. Your installation folder may be different.

  1. The project manager is started, and project file "SAMPLE15.PRJ" is opened.

  2. Select "Build" from Project Manager's "Project" menu or click on the Build button in the Project Manager toolbar.

    After the build terminates, check that MAIN.EXE is created.

Debugging the Program

You can execute this program under the control of the COBOL Debugger by selecting Debug from the Project menu.

Executing the Program

To execute the linked program, select Execute from the Project menu.

Sample 15 requires no special execution environment information to be set.

The interface is very basic - simply enter an employee number 1, 2 or 3 to display details for that employee. After the details are displayed enter Y or N to terminate or continue.