For example, an OLE automation server which wants to provide OrderedCollection functionality can create its own OrderedCollection object, and implement "add" and "at" methods which simply delegate these functions to the OrderedCollection.
For example, the attributes of a circle are its radius and the coordinates of its center. The actual code for implementing circle objects might require other data items for calculations, but these would not be considered part of the attributes for that object.
One use of Callback objects is to handle GUI event processing. For example, the Phonebook GUIController has an Add method for adding new records. A Callback to this method in GUIController is attached to the pushbutton object for Add, and whenever the pushbutton is clicked it invokes this Callback.
A class consists of nested COBOL programs, which correspond to class object and instance object methods. Each class starts with an identifier naming the class and the class from which it inherits. When a class is loaded at run-time, the OO run-time system creates the class object.
If the program itself is an Object COBOL class, the Class-Control paragraph also lists its superclass, and the class itself.
The class object itself does not have the same behavior and methods as the instance objects which it creates. By analogy, a biscuit cutter is a template for creating biscuits; however, you can't eat a biscuit cutter and you can't stamp a biscuit from another biscuit.
In Object COBOL, all the methods and data for a class object and the instance objects which it creates are represented by a class program.
The class object is created at run-time when a class is loaded.
There are also classes to implement collections, exception handlers, Callbacks, and GUI interfaces.
For example, the public interface to an OrderedCollection describes how you can add, retrieve and remove elements. The Collection framework describes how OrderedCollections (and other types of collection) communicate with the objects they are storing as elements.
Each class inherits all the methods of its superclass, so a class ultimately inherits all methods all the way up to a root class. A class object inherits the class methods of its superclass, and an instance object inherits the instance methods of its superclass. In this Object COBOL implementation, a class has only one immediate superclass. The superclass is named in the INHERITS clause of the CLASS-ID header.
The methods and data for instance objects are defined in the object program, which is nested within the class program. The object program starts with the header OBJECT and finishes with END OBJECT.
The invoke
verb enables you to send messages. For example:
invoke anOrange "peel" returning segments
The method selector "peel" invokes the peel method in anOrange. Data is returned from the method in data item SEGMENTS.
This release of Object COBOL supports dynamic binding only.
There are two types of object: classes and instances. A class object is created when you register a class; an instance is created whenever you send an appropriate message to the class object which defines that instance. The Object COBOL run-time system allocates each object its own data area in memory. There can be many instance objects of the same type within a run-unit, but there can only be one class object of each type.
You always give the object handle when you send a message; the OO RTS uses the handle to find the object which should receive the message. You store object handles in data items of type OBJECT REFERENCE.
Polymorphism enables you to send the same message ("printStatement") to any type of account object and get appropriate results.
You can use SELF exactly like any data item of type Object Reference, so you can also pass it as a parameter to other methods.
Contrast with a message, which is sent to a single specific object. if the object does not understand the message it raises a run-time exception.
Unlike SELF, and SELFCLASS, SUPER is not a data item containing an object handle; you can't pass SUPER as a parameter to a method.
Copyright © 1999 Micro Focus Limited. All rights reserved.
This document and the proprietary marks and
names used herein are protected by international law.