Java Reference
In-Depth Information
As you can see, this approach can meet some basic object-oriented goals.
Generic behavior is encapsulated in MYSUB, and more specific behavior is estab-
lished in NEWSUB.
M ORE COBOL O BJECT -O RIENTED D ESIGN P ATTERNS
There is an even more useful example of inheritance-like behavior in COBOL. As
you've seen, a COBOL subroutine is generally a serviceable mechanism to encap-
sulate some algorithm. Sometimes, however, the restrictions of a COBOL subrou-
tine hinder its use in complex solutions. This is because the subroutine is written as
a black box , a device with well-defined inputs and equally well-defined outputs.
What happens if your requirements are such that the subroutine fulfills 80 or
90 percent of your requirements but not 100 percent? Normally, you'll have to
choose between these solutions:
Extend the function of the subroutine to meet your requirements.
Code the specific requirements in your CALLER.
Either solution is fine, provided it is technically possible, but each has some po-
tential deficiencies:
What if these requirements are too complex or inappropriately unique for in-
clusion in a subroutine? What if my extensions might break the original design
objectives of the subroutine?
What if the requirements can only be met by modifying the subroutine's logic,
not simply its input parameters? For example, it may be necessary to insert ad-
ditional processing logic into MYSUB's evaluation function. This may not be
possible in either NEWSUB or in CALLER.
Faced with these dilemmas, COBOL developers often make the fateful choice
to copy the subroutine's logic into another program and rework it to meet the re-
quirements at hand. This is a classic example of how reuse objectives are over-
whelmed by the complexities of a particular requirement. There is, however, a
potential third solution to subroutine reuse in a complex environment. This solu-
tion requires planning in advance, but it can yield substantial benefits.
Some of the object-oriented benefits of inheritance can be achieved if a subroutine
returns to its caller before completing a function so that the caller can extend or
complete that function.
Search WWH ::




Custom Search