| Front Page | News Headlines | Technical Headlines | Planning Features | Advanced Search |
Design 3000 Plus Sponsor Message


Object Oriented COBOL

By Shawn M. Gordon

I was recently talking about OO COBOL with some friends and we came up with a number of questions. By researching the ’net I was able to come up with the following answers. You can think of this as a FAQ for OO COBOL.

What is an object? An object is an item in the real world. You are an object and so am I. Your pen, car, and TV are objects. Objects can also be design entities in software design documents and implementation entities in an application.

What is a class? Objects with common characteristics — this could be in terms of data or behavior or both.

What is a method? A piece of OO COBOL code.

What types of methods are there? In general there are class methods and instance methods.
What is the difference between a class method and an instance method? In practice in OO COBOL the real difference between a class method and an instance method breaks down into two parts.

How you call the method: A class method is called by preceding the call with the name of the class — while an instance method is preceded with an object reference to the instance of the class that has the method you wish to invoke.

How many copies of the method there are at any given time (again, in practice in run time implementation there is only one copy of code as in an XL implementation but there can be 1 to N copies of the data associated with a method).

How do you tell the difference between a class method and an instance method when looking at code? The class methods will be inside of this section of code:

End Class-Object.
While instance methods will be inside this section of code:
End Object.
What does a simple method look like?

Method-Id. “sampleMethod”.
Linkage Section.
01 LS-VAR1 pic 9.
Procedure Division using LS-VAR1.
display ‘Variable Value (‘LS-VAR1’)’.
End Method “sampleMethod”.

This sample shows a very simple method. The method can have most of the standard sections that a standard COBOL program can have. These include but are not limited to:

Environment Division.
Input-Output Section.
Data Division.
File Section.
Working-Storage Section.

This means most of what you see should be familiar to you. There is no difference in how you code a class method and how you code an instance method! They look the same. Remember that class methods and instance methods do not share the same global storage areas. In other words, you can have data that is global to all class methods and you can have data that is global to all instance methods. The two areas can not share data directly. They can however share data and in fact this is pretty common.

What new vocabulary do I need to learn for OO COBOL that is different than standard COBOL?
That is a good question, and believe it or not, only a few new verbs and COBOL sections are required to code OO COBOL. Some of these are:

• self: a reserved word that is defined as the object reference to the current instance of this class. It is interchangeable with the real object reference as a variable.

• super: a reserved word that is defined as the object reference to the parent class for this instance of a class.

• invoke: a reserved verb that precedes the class or instance handle when making OO method calls. Think of this as you might the CALL verb.

We have already covered the fact that you have a couple of new sections that delimit the class and instance methods in a program.

One other paragraph heading that is very important and is the same for class and instance sections is the Object-Storage Section.

What is the Object-Storage Section? In a class, an instance method is the data that is global to the class or to all instances of a class. Again the class section of the code has its own Object-Storage Section and the Instance Method section of the code has its own Object-Storage Section.

That is the basics of what you need to know to start looking at and eventually coding OO COBOL. It’s not all that bad: the syntax is pretty easy, but thinking and designing code in terms of objects is what is going to be the hurdle. If you have been writing modular code for a while, then the hurdle may not be too great.

I would like to recommend a book that seems to be pretty recent and covers OO COBOL nicely, “An Introduction to Object Cobol” by E. Reed Doke and Bill C. Hardgrave.

Shawn Gordon, whose S.M. Gordon & Associates firm supplies HP 3000 utilities, has worked with 3000s since 1983.


Copyright The 3000 NewsWire. All rights reserved.