Example: The checking account class shown below describes a factory object, which is called the checking account factory object. To create a new checking account instance, a method in the checking account factory object is used. To keep track of the number of checking account instances a data item in the factory object can be used. Whenever a new instance is created, 1 can be added to the value; whenever an instance is removed, 1 can be subtracted from the value. Sample code for the checking account factory object could be as follows: CLASS-ID. CheckingAccount INHERITS Base. ENVIRONMENT DIVISION. CONFIGURATION SECTION. REPOSITORY. CLASS Base. FACTORY. DATA DIVISION. WORKING-STORAGE SECTION. 01 number-of-accounts PIC 9(5). PROCEDURE DIVISION. METHOD-ID. newAccount. create-account. add 1 to number-of-accounts. ... END METHOD. END FACTORY OBJECT. ... |