Chapter 25: Requirements-based Vocabulary Tutorial

Requirements-based vocabulary enables you to create new verbs and functions related to types of application you are working on. This tutorial demonstrates this feature, using the bank account classes introduced in the chapter Inheritance Tutorial.

This tutorial uses Micro Focus alternatives and extensions to the ISO 2002 OO COBOL syntax.

This tutorial consists of the following sessions:

  1. Vocabulary for the Account Classes
  2. Using Requirements-based Vocabulary

Vocabulary for the Account Classes

In this session you will load an example application similar to the one used in the inheritance tutorial. The only difference is in the driver program, bank2.cbl, which uses a vocabulary defined for the account classes to send them messages, instead of the Invoke statement.

To look at the Bank vocabulary example:

  1. Start the Net Express development environment.
  2. Click File > Open, and open Examples\Net Express IDE\Bank\Vocab.app.
  3. Rebuild the project.

    This program uses two copyfiles account.if and saccount.if. They are the class interface files which define new vocabulary for use with the Account and SavingsAccount classes. Because the methods of Account are inherited by all types of account, with no interface changes, the vocabulary defined in account.if applies to all the account classes. The saccount.if file defines extra vocabulary appropriate to SavingsAccount (and HighRateAccount which is a subclass of SavingsAccount).

  4. If the contents of account.if are not displayed in the editor window, right-click on the name and click Show Copyfile on the popup menu.

    The class-id header at the start of account.if defines it as an external class. The Compiler does not generate any code for external classes.

  5. Scroll down to the "openAccount" method.

    This has the same method-id, linkage section and procedure division headers as the "openAccount" method in account.cbl. However, there are no executable statements in the Procedure Division. Instead, there is a syntax definition of a new verb, create.

  6. Look at the definition of the create verb.

    Below the procedure division header is the Invoked As phrase. The words in brackets [ ] are noise words, included for readability. You don't have to include them when you use the "create" verb.

    Words inside angle brackets <> are the parameters to the routine, with the exception of <self>. <self> is the object reference to the object that receives the message. Every parameter in the definition of the verb is in the procedure division header using and returning clauses. The Procedure Division and Linkage Section headers match exactly those in the openAccount method of the Account class itself.

    The syntax for defining new verbs and functions is covered in the chapter Requirements-based Vocabulary.

This is the end of the first session. Do not shut down Debugger as the next session carries on directly from this one.

Using Requirements-based Vocabulary

In this session you will debug bank2.cbl, which does exactly the same as bank1.cbl, which you debugged in the inheritance tutorial. However it does it using the new verbs defined in the interface files you looked at in the previous session of this tutorial.

To debug the vocabulary example source code:

  1. Click Debug > Start Debugging

    The text window shows the code for bank2.cbl, with the statement below tag B002 highlighted ready for execution.

  2. Step the lines below tag B002.

    The message to open a new CheckAccount is sent by the new verb create, which is defined in account.if. Execution switches to the "openAccount" method of Account (CheckAccount inherits the "openAccount" method from Account).

  3. Step through the account creation code until execution returns to the line below tag B003 of bank2.cbl.
  4. Step through the code of bank2.cbl until you reach tag B008.

    As you step through the code, you can see how the same verbs can be used for SavingsAccounts and CheckAccounts.

  5. Step the line below B008.

    This conditional statement uses the balance function. This is an example of a function definition. You can use it in the same sorts of ways as you can use an intrinsic COBOL function; for example in a conditional statement or as part of a Compute statement. This function is defined in account.if along with the other verbs used in this tutorial.

  6. Step through the code until you reach the Stop Run statement.
  7. Click Debug > Stop Debugging.

This ends this tutorial on Requirements-based Vocabulary. You can study account.if and saccount.if to see how you can define vocabulary for any objects you create.

Summary

This tutorial covered the following:


Copyright © 2009 Micro Focus (IP) Ltd. All rights reserved.