The Object Oriented Paradigm

This page is a quickie introduction to Object Orientation. I don't pretend to be an expert -- surely you can find a more authoritative discussion elsewhere. I provide it only as a convenience for those visiting my pages on OO COBOL.

Objects

An object has behaviors and an internal state.

In OO COBOL the behaviors are called methods. They correspond to member functions in C++. Whatever jargon you use, a behavior amounts to a subroutine call, where an implicit parameter identifies the object whose method is being invoked.

The internal state consists of the data stored inside the object. In OO COBOL this data is accessible only to the methods of the object. From the standpoint of any other code, the object consists entirely of behaviors, except that the result of the behaviors may depend on the internal state. Some methods may change the internal state.

Classes

A class is a category of similar objects. All objects of the same class have the same range of potential states and behaviors. A particular object is sometimes called an object instance, or simply an instance, of the class. There may be multiple instances of a given class in existence at the same time.

Dog is a class. Lassie is an instance of Dog.

Inheritance

A class may be a subclass (or "child" class) of a broader, more generic superclass (or "parent" class). Instances of the subclass have all the states and behaviors associated with the superclass, but may have other more specialized traits as well.

Every Dog is a Carnivore. Carnivore, in turn, is a subclass of Mammal, which is a subclass of Vertebrate (actually Chordate, if you want to be picky). Lassie inherits Hair and MammaryGlands from Mammal, and a Hunt method from Carnivore.

(I have described what is sometimes called "public" inheritance. C++ also provides "private" and "protected" inheritance, which -- oh, never mind. COBOL doesn't have them.)

Polymorphism

A subclass inherits all the behaviors of the superclass, but it may override a behavior with its own variation of that behavior.

If you have an object reference to a Carnivore, you can invoke its Hunt method without knowing what kind of Carnivore it is. At runtime, if it happens to be a Dog, it will chase. If it happens to be a Cat, it will stalk.

Multiple Inheritance

A class may have two or more parent classes, inheriting traits from each.

This scenario invites confusion, because two or more parents may have methods of the same name. There needs to be some rule to resolve the conflict. As a result, some OO languages (e.g. Java) don't allow multiple inheritance.

(The two parents may also have data elements with the same name. In COBOL, however, this possibility is not a problem. The data elements of a class are not visible to any other classes, even child classes.)

Lassie is not just a Dog, she is a DomesticDog, which inherits from Dog and Property. Like other instances of Property, she has an Owner, a PurchasePrice, and a Depreciate method.


[home]Cobol Home [OOC]OO Cobol