|
|
The Micro Focus COBOL as a Class Pre-processor
Micro Focus Object COBOL is a subset of the standard proposed by the ANSI X3J4 committee, due originally in 1997, then 1998 or beyond.
A Micro Focus investigation into Object Orientation and Procedural COBOL soon showed that it is possible to convert existing procedural COBOL to OO COBOL, enabling existing legacy code to enter the OO world with the minimum of problems and the minimum of work. This can also be done in such a way that existing procedural code programmers could use and maintain this code without the extensive retraining most OO "experts" claim is required.
Making use of OO facilities while still coding in Procedural code.
By the use of the CASC (COBOL as a Class) pre-processor to convert procedural COBOL to OO COBOL during the compilation process it is possible to convert the code without any additional utilities and without the user requiring any knowledge of the structure of the OO code that is produced. Normal well structured COBOL code converts easily to OO Class code (Even spaghetti code will convert). This new code will interface to existing procedural code and to new OO COBOL code without the need for user changes. This enables one to achieve some of the benefits of object oriented development such as incremental development and improved code reuse through the inheritance mechanism. It is also possible to write the subclass code in standard Procedural COBOL. When the user runs the debugging tools (Micro Focus Animator) on the resulting OO code with the close integration of MF development products it is presented to him in its original Procedural form. This enables companies to start making use of Object orientation with no retraining of existing staff and no need to invest heavily in new OO skills.
The philosophy used in the conversion of procedural code to OO code.
The basic philosophy of the conversion is quite simple. Existing Working-storage is converted into Object-storage (the Objects data), all paragraphs and sections within the code are converted to methods , and all perform statements are converted to invoke statements (Invoke is the new COBOL syntax to send a message to an Object, ie. invoke a method on an object). Of course user code is never quite this straightforward and special techniques must be used to handle special situations. These include:
Ease of use of the Pre-processor
CASC is activated by a checker directive and parameters to this directive. This can be set in the standard way for checker directives, dynamically on the command line, in a directives file, or in the source code itself. No additional process is required other than to compile the original procedural code as you normally have to do to produce executable code.
Convert to OO source code or continue in Procedural Code
CASC provides the choice of either converting your source code to Object COBOL source or, because the conversion is done at compile time, of continuing to work in procedural code.
If you intend to switch to OO design then at some point you will probably want either to rewrite from scratch or convert the existing code. If you just want to modify an existing working system then it may be better to keep it in procedural code and make use of sub classing to produce the modifications, without having to alter the original. This can all be done using procedural code and CASC.
Converting to Object COBOL should NOT cause great concern, it only required an additional 8 lines of syntax to add Object Orientation to COBOL, and it is easier to teach Object Orientation with COBOL to an existing COBOL programmer than to teach a new language.
Class Code or Instance Code
By default CASC produces CLASS code. The advantage of this is it can be interfaced to without any changes to the calling code. That is with the Micro Focus Object COBOL checker and run time it is possible to CALL a class. It is possible to create INSTANCE code, but how useful this is will depend on how well defined the original code is. Also to access instance code then you must use the new INVOKE verb as it is impossible to call this code.
Converting Procedural COBOL code to OLE2 server programs and SOM objects.
Micro Focus Object COBOL offers seemless integration with OLE2 and SOM objects. So to convert procedural COBOL code to OLE2 and SOM was just an extension to the above. Converting to these standards not only provides the benefits of OO but also allows seemless interfacing to other languages. Obviously when converting to OLE2 and SOM it is no longer possible to call the code as the interface must now conform to external standards. In this case additional methods are created within the converted code to enable to passing of the original programs parameters to and from the OLE2/SOM objects. In this case the program issuing the call must now be changed to issue the necessary invokes. However this is a minor change and can be made even easier by using a small intermediate program which is still called but contains an invoke of the new code.
Summary
The conversion of COBOL to object orientation is not the insurmountable problem other language vendors would like everyone to believe. It is in fact a straightforward step to start gaining the benefits of OO and requires no more than a couple of hours retraining of existing staff. Having taken this step the programmer may then at his own pace explore the full functionality of Object COBOL, it is not necessary to rewrite code, convert data, and retrain programmers, before gaining the benefits of OO.
Laurence Gray
OO Development Team
Micro Focus
Drop me a note with you thoughts or comments ...