Java Reference
In-Depth Information
If a subroutine allows this type of interaction, the caller can modify the sub-
routine's functions to meet its unique requirements. With this approach, it would
not always be necessary to change the subroutine's functions in order to meet new
requirements. Think of this type of subroutine not as a black box, but as a box with
gloves that extend into the box. These gloves allow you to safely manipulate the in-
ternal workings of the box.
Believe it or not, it is possible to implement a form of inheritance with COBOL,
even though the language does not directly support this concept. To do so, the in-
terface will include a set of options switches and “traffic-cop” items. The subroutine
and the calling program use these to coordinate the program flow. The option
switches are set by the calling program to indicate that a particular function is to be
extended. The subroutine checks this flag and, if required, returns to the calling
program before completing the function. The calling program then checks the traf-
fic-cop item to see if a mid-function return has been requested. If so, the caller can
perform some additional code to extend the subroutine's function and then return
to the subroutine. The subroutine checks the traffic cop and resumes processing the
incomplete function.
In Figure 5.5, MYSUB-CONTROL is extended to include the options and traffic-
cop items. Using these variables, the calling program can request that any of the func-
tions available with ACTION-SWITCH be extended by the caller. MYSUB returns
control to the caller before completing the function. The caller then performs any ad-
ditional logic for that function as required, and then returns to the subroutine.
FIGURE 5.5
Extending a COBOL subroutine.
Search WWH ::




Custom Search