A class extension enables you to add extra functionality to an object COBOL class without changing the original source code.
The difference between extending a class with a class extension as opposed to using inheritance is that the class extensions
are inherited by all existing subclasses. For example, if class A has a subclass, class B (B INHERITS FROM A), you can add
methods to class A by subclassing it to create subclass C. However, class B does not inherit the methods of class C, because
it is a subclass of A. If you extend class A with a class extension, X, the effect at run time is the same as if you had changed
and recompiled class A: class B inherits all the extra methods in class X.
- Extension-name-1 must not be the same as class-name-1.
- Extension-name-1 in the END CLASS header must be identical to the extension-name-1 specified in the preceding Class-ID paragraph.
- Class-name-1 must be the name of a class specified in the Class-Control paragraph.
- The Data Division of the class-body may contain an empty Object-Storage Section. The only other sections that may be specified
in the Data Division of a Class Extension are the Working-Storage Section and the Linkage Section.
- Statements in the class extension may reference data declared in class-name-1 only when both the following cocnditions are
- The DATA IS PROTECTED or DATA IS RESTRICTED phrase is specified in the Class-ID paragraph of class-name-1
- The WITH DATA phrase is specified in the Class-ID paragraph of the class extension.
- The EXTEND clause specifies a class extension. A class extension adds methods to an object class. The methods specified in
extension-name-1 are inherited by all subclasses, existing and new, of class-name-1.
- During the execution of a run unit, a COBOL call statement to extension-name-1 must be executed before any of the methods
in the class extension are invoked. This registers the methods in the class extension with the OO run-time system.