Example: defining a client
The following example shows a small client program of the Account class.
The program does this:
- Invokes a factory method createAccount to create an Account instance with a default balance of zero
- Invokes the instance
method
credit
to deposit $500 to the new account - Invokes the instance method
print
to display the account status
(The Account class was shown in Example: defining a method.)
cbl dll,thread,pgmname(longmixed)
Identification division.
Program-id. "TestAccounts" recursive.
Environment division.
Configuration section.
Repository.
Class Account is "Account".
Data Division.
* Working data is declared in LOCAL-STORAGE instead of
* WORKING-STORAGE so that each thread has its own copy:
Local-storage section.
01 anAccount usage object reference Account.
*
Procedure division.
Test-Account-section.
Display "Test Account class"
* Create account 123456 with 0 balance:
Invoke Account "createAccount"
using by value 123456
returning anAccount
* Deposit 500 to the account:
Invoke anAccount "credit" using by value 500
Invoke anAccount "print"
Display space
*
Stop Run.
End program "TestAccounts".
Example: defining a factory (with methods)