Inheritance in OO COBOL
| INHERITS | |
| SUPER | |
| FACTORY |
INHERITS
A class inherits from another with the INHERITS phrase. The child gets the parent methods and data, and can override any method by redefining its METHOD-ID:
CLASS-ID. Manager INHERITS 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.
INVOKE SUPER "Bonus"
ADD 1000 TO WS-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 OBJECT REFERENCE Employee.
Next: Intrinsic functions
Article author: Arthur Isaev