OO COBOL

0. Intended Use

COBOL Object Orientation and associated capabilities provides facilitiesfor developing object-oriented programs using the COBOL programming language.(For the rest of this Features Matrix entry, these facilities will be referredto as OO COBOL.) These facilities are currently part of a proposal[Obi94] to extend standard COBOL as the result of work by an X3J4 taskgroup, and have not been officially approved by X3J4.

1. Basic Concepts

OO COBOL includes the following:

  1. The ability to define classes, comprising class object definitionsand object definitions.
  2. The ability to define data encapsulated inside class objects and objects.
  3. The ability to define methods for class objects and objects.
  4. The ability to use inheritance and define subclasses.
  5. The ability to use polymorphism and interfaces for maximum flexibility.
  6. The ability to define data items able to hold references to objects.
  7. The ability to invoke methods on objects.
  8. The ability to create and manage objects as required.
  9. The ability to use objects as a normal part of COBOL programming indeveloping new programs and maintaining existing programs.

2. Objects

An object is a single entity comprising data and methods. An objectbelongs to a class. A class describes the structure of the data and themethods that apply to all the objects belonging to that class. A classalso has a single class object with data and methods. The class objectis an object that acts as a creator of objects.

Each object has an interface comprising the names and parameter specificationsfor each method supported by the object. Each class defines two interfaces:an interface defining the methods supported by the class object (the classobject interface), and the interface to be supported by each instance ofthe class.

Interfaces independent of class objects or class instances may be definedby listing the method names and parameter specifications supported by thoseinterfaces. Such an interface may be specified in the declaration of anobject identifier to restrict the objects that may be referred to by thatidentifier to objects whose interfaces conform to the specified interface.Conformance is a relationship between interfaces. One interface is saidto conform to a second interface if an object that implements all the methodsspecified in the first interface may be used anywhere an object that implementsall the methods specified in the second interface may be used. A formaldefinition for conformance is included in the specifications [Obi94].

See also entry under 7. Types and Classes.

Editor's Note: The concept of conformance in OO COBOL resembles thatin the Emerald language.

2.1 operations

2.2 requests

A request to execute a named method on a given object is called an invocation.Invocations may be specified in two ways. An in-line method invocationis indicated by two contiguous colon characters. For example, the followinginvokes method FOO of object OBJ, with parameter PARM):

   OBJ :: FOO(PARM)

An explicit invocation is specified using the INVOKE statement. TheINVOKE statement corresponding to the above invocation would be:

   INVOKE OBJ FOO USING PARM RETURNING ANS 

The INVOKE statement allows the name of the method to be invoked tobe contained in a variable. In addition, parameters can be passed BY CONTENT(by value) or BY REFERENCE, and these options can be specified separatelyfor each parameter in different INVOKE statements.

2.3 messages

2.4 specification of behavioral semantics

2.5 methods

The procedural code in an object is placed in methods. Each method hasits own method-name and its own Data Division and Procedure Division. Whena method is invoked, the procedural code it contains is executed. A methodis invoked by specifying a reference to the object and the name of themethod. A method may specify parameters and a returning item. Data definedwithin a method is local to that method.

The structure of a method definition is:

IDENTIFICATION DIVISION.METHOD-ID. method-name-1 
      { PUBLIC     }   IS { RESTRICTED } [PROTOTYPE] [OF [CLASS-OBJECT OF] class-name-1]      { PRIVATE    } [Method Environment Division] [DATA DIVISION. Method Data Definitions]
[PROCEDURE DIVISION 
   [       {{ INPUT  }             }     ]   [ USING {{ OUTPUT } data-name-1 } ... ] RETURNING data-name-2].   [       {{ I-O    }             }     ] 
Method Procedure Statements] END METHOD method-name-1.

2.6 state

Object state in OO COBOL consists of data items (which may be structured)defined in class object or object data divisions, and data defined withinmethods of class objects or objects. See entry under 7. Types and Classes,for the structure of class definitions, and entry under 2.5 methodsfor the structure of method definitions.

2.7 object lifetime

The life-cycle for an object begins when it is created, and ends whenit is destroyed. An object of a given class created using a CBL-CREATEmethod associated with the class object for that class. Object classesmay be defined as transient, persistent, or collectable.If a class is transient, the class objects and objects of the classare destroyed automatically when the run unit (program execution) terminates.If a class is persistent, the class object and objects of the classare destroyed only when a CBL-DISCARD method is invoked on them. Persistentclass objects and persistent objects exist from one run unit to the next.If a class is collectable, the class is transient and hence theclass objects and objects of the class are destroyed automatically whenthe run unit terminates. In addition, objects of the class may be destroyedbefore the run unit terminates by the run unit's garbage collector, whenthey can no longer be referenced by transient objects within the run unit.(If a reference to a transient object is stored in the object data or classobject data of a persistent object, the results of using this referenceare undefined).

2.8 behavior/state grouping

OO COBOL implements a classical object model.

2.9 communication model

The programming model for OO COBOL is synchronous.

2.10 events

3. Binding

When a method is invoked on an object, the invocation is bound to amethod implementation in the following way.

See also entry under 8. Inheritance and Delegation.

4. Polymorphism

Polymorphism is a feature that allows a given statement to do differentthings. In OO COBOL, the ability for a data item to contain various objectsof different classes means that a method invocation on that data item canbe bound to one of many possible methods. Sometimes the method can be identifiedbefore execution, but in general, the method cannot be identified untilrun time.

A data item can be declared to contain objects of a given class or anydescendant of that class; it can also be declared to contain objects thatconform to a given interface. When a given interface is used, the classesof the conforming objects may be completely unrelated. These options arespecified using the various forms of the USAGE IS OBJECT REFERENCE declarationfor data items, as given below:

                 [ interface-name-1                        ]                 [                                         ]                 [ [ { CLASS-OBJECT }    ]                 ]OBJECT REFERENCE [ [ {              } OF ] SELF            ]                 [ [ { CLASS        }    ]                 ]                 [                                         ]                 [ [ CLASS-OBJECT OF ] class-name-1 [ONLY] ]

See also entry under 8. Inheritance and Delegation.

5. Encapsulation

Objects may only be accessed through the operations defined in the object'sinterface. In defining an object, methods can be specified as PRIVATE,RESTRICTED, or PUBLIC. Data can be specified as PRIVATE or RESTRICTED (thereis no public data). If the scope of a data (method) name is declared asPRIVATE, this means that the data item (method) can be accessed (invoked)only from methods declared in the same class object or object definitionas the data item (method). If the scope of a data (method) name is declaredas RESTRICTED, this means that the data item (method) can be accessed (invoked)from methods declared in the same class object or object definition asthe data item (method), or from methods declared in a class object or objectrespectively that inherits from the class definition that contains thedeclaring class object or object definition. If the scope of a method nameis declared as PUBLIC, this means that the method can be invoked from anyprocedural statement that has access to an object identifier that may containthe class object or object of the class.

6. Identity, Equality, Copy

OO COBOL defines the concepts of object reference and objectidentifier. In OO COBOL, an object reference is a value thatuniquely identifies an object for the lifetime of the object. No two objectshave the same object reference, and every object has at least one objectreference. Note that it is permitted to have more than one object referencefor any given object, provided the requirements of the specification arefully met, but it is sufficient and in general expected that a given objectwill have precisely one object reference.

In OO COBOL, an object identifier is an identifier (essentiallya data item name) that identifies an object. It may be declared in theData Division as a data item declared with USAGE IS OBJECT REFERENCE, orin the Environment Division. There are also three predefined object identifiers,SELF, SUPER, and NULL. SELF and SUPER both reference the object of thecurrently executing method, and are used in invoking other methods associatedwith that object from within that method. If SUPER is used, method bindingwill ignore all methods defined in the same class as the executing method,and all methods defined in any class which inherits from that method.

The CBL-NULL class is a predefined class. There are no instances ofthis class. The NULL object is the CBL-NULL class object. A reference tothe NULL object is placed in every data item declared with USAGE IS OBJECTREFERENCE when storage for that data item is allocated, except when thatdata item is declared as a redefinition of another data item. Invokingany method on the NULL object causes the exception EC-OO-NULL to be raised.

Object identifiers may be compared for equality or inequality. Two objectidentifiers are equal if the objects referred to by those identifiers arethe same object.

7. Types and Classes

Any object in OO COBOL belongs to a class. A class describes the structureof the data and the methods that apply to all the objects belonging tothat class. A class also has a single class object with data and methods.The class object is an object that acts as a creator of objects. Each classdefines two interfaces: an interface defining the methods supported bythe class object (the class object interface), and the interface to besupported by each instance of the class. The structure of a class definitionis given below.

IDENTIFICATION DIVISION. 
                          { TRANSIENT [COLLECTABLE] } CLASS-ID. class-name-1 IS {                         }                          { PERSISTENT              }    [INHERITS {class-name-2}...].[Class Environment Division] [IDENTIFICATION DIVISION. CLASS-OBJECT. [Class Object Environment Division][Class Object Data Division] [PROCEDURE DIVISION. [{Class Methods}...]] END CLASS-OBJECT.] [IDENTIFICATION DIVISION. OBJECT. [Object Environment Division] [Object Data Division] [PROCEDURE DIVISION. [{Object Methods}...]] END OBJECT.] END CLASS.

Interfaces independent of class objects or class instances may be definedby listing the method names and parameter specifications supported by thoseinterfaces. Such an interface may be specified in the declaration of anobject identifier to restrict the objects that may be referred to by thatidentifier to objects whose interfaces conform to the specified interface.Conformance is a relationship between interfaces. One interfaceis said to conform to a second interface if an object that implements allthe methods specified in the first interface may be used anywhere an objectthat implements all the methods specified in the second interface may beused. A formal definition for conformance is included in the specifications[Obi94].

OO COBOL defines a built-in class called CBL-BASE that user-definedclasses can inherit from. This class provides essential functionality forcreation and management of objects. [Obi94] describes a minimal implementationof the CBL-BASE class, which is given below. The actual definition of theCBL-BASE class is implementor defined, but should provide the same or greaterfunctionality. Implementors may define data and other methods for the classobject interface, the object interface, or both.

The following are examples of the definitions of some of these methods.They illustrate some of the basic functionality of OO COBOL classes, andalso some of the syntax of method definition in OO COBOL.

The CBL-CREATE method is a class method that allocates storage for anobject and initializes its object data to the values specified in VALUEclauses. The method requires system services, and thus only a skeletoncan be specified in OO COBOL.

  METHOD-ID. CBL-CREATE IS RESTRICTED.   DATA DIVISION.  LINKAGE SECTION.  01 CREATED-OBJECT USAGE OBJECT REFERENCE SELF.  PROCEDURE DIVISION RETURNING CREATED-OBJECT.     ...     EXIT METHOD.  END METHOD CBL-CREATE.

The CBL-NEW method is a class method that is used to create objectsof a class. It makes use of the CBL-CREATE method, and can be written inOO COBOL.

  METHOD-ID. CBL-NEW.  DATA DIVISION.  LINKAGE SECTION.  01 CREATED-OBJECT USAGE OBJECT REFERENCE SELF.  PROCEDURE DIVISION RETURNING CREATED-OBJECT.     INVOKE SELF "CBL-CREATE" RETURNING CREATED-OBJECT     INVOKE CREATED-OBJECT "CBL-INITIALIZE"     EXIT METHOD.  END METHOD CBL-NEW.

The CBL-ISPERSISTENT method returns an indicator as to whether thisobject is persistent. Only a skeleton can be written in OO COBOL.

  METHOD-ID. CBL-ISPERSISTENT.  DATA DIVISION.  LINKAGE SECTION.  01 RESULT PIC X.     88 IS-TRUE VALUE "Y".     88 IS-FALSE VALUE "N".  PROCEDURE DIVISION RETURNING RESULT.     ...     EXIT METHOD.END METHOD CBL-ISPERSISTENT.

8. Inheritance and Delegation

The INHERITS clause of a class definition specifies the names of classesthat are inherited by the class being defined. A predefined CBL-BASE classis defined that COBOL classes can inherit from. Although it is not requiredthat classes inherit from CBL-BASE, this is the only way to write (in standardCOBOL) a creatable class. Class inheritance in OO COBOL is an implementationconcept. Interfaces can be defined that inherit the interfaces of classesand/or other interfaces. Multiple inheritance is supported for both classand interface inheritance. Rules are defined to insure that implementationinheritance implies interface conformance, even in cases of multiple inheritance.The collection of class and interface definitions effectively form a singlesubtype hierarchy defined by the conformance relationships between theobject, class object, and interface definitions.

See also entry under 7. Types and Classes.

9. Noteworthy Objects

9.1 relationships

9.2 attributes

Objects are accessed through interfaces consisting of sets of methods.Data cannot be defined as PUBLIC, and therefore cannot be visible at anobject interface.

9.3 literals

Ordinary COBOL literals are supported.

9.4 containment

9.5 aggregates

Ordinary COBOL aggregates are supported. The definition of parameterizedcollection objects is being investigated.

9.6 other

10. Extensibility

10.1 Dynamic

10.2 Metaclasses/Metaobject Protocol

10.3 Introspection

11. Object Languages

12. Semantics of Base Classes (+ type constructors)

13. Background and References

[Obi94] Document X3J4/94-0191 (X3H7-94-10), Object Orientation, RaymondObin, 22 February, 1994.

[Top94] Andrew Topper, "Object-Oriented COBOL Standard", ObjectMagazine 3(6), February 1994, 39-41.

featuresmatrix intro page