Inheritance in OO COBOL

INHERITS

A class inherits from another with INHERITS FROM. The child gets the parent methods and data, and can override any method by redefining its METHOD-ID:

IDENTIFICATION DIVISION. CLASS-ID. Manager INHERITS FROM Employee.

SUPER

SUPER reaches the parent version of a method from inside the child, so an override can extend rather than replace:

METHOD-ID. Bonus. DATA DIVISION. LINKAGE SECTION. 01 LS-BONUS PIC 9(7)V99. PROCEDURE DIVISION USING LS-BONUS. INVOKE SUPER "Bonus" USING LS-BONUS ADD 1000 TO LS-BONUS. END METHOD.

FACTORY

The FACTORY section holds class-level (shared) methods, and OBJECT holds instance methods. An object reference lives in a data item declared with USAGE OBJECT REFERENCE:

01 WS-EMPLOYEE USAGE OBJECT REFERENCE Employee.

The code on this page was not run: GnuCOBOL 3.2.0 does not implement OO COBOL.

Article author: Arthur Isaev