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
MAIN.COB (COBOL source program)
MEMBER.COB (COBOL source program)
ADDRESS.COB (COBOL source program)
SAMPLE15.PRJ (Project file)
SAMPLE15.CBI (Compiler option file)
SAMPLE15.TXT (Program guide)
COBOL Functions used in Sample 15
Object-oriented programming function
Class definition (Encapsulation)
Object generation
Method invocation
Project management
Object-Oriented Syntax used in Sample 15
INVOKE and SET statements
REPOSITORY paragraph
Class, object and method definitions
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.
The project manager is started, and project file "SAMPLE15.PRJ" is opened.
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.