FactoryObject is an object method that provides a standard mechanism for acquiring access to the factory object of a class. Described with COBOL semantics, the interface for the FactoryObject method is as follows:
Interface-id. BaseInterface. Procedure division. Method-id. FactoryObject. Data division. Linkage section. 01 outFactory usage object reference factory of active-class. Procedure division returning outFactory. End method FactoryObject. End Interface BaseInterface.
General rules
If the FactoryObject method is called for an object, it determines the class of the object and references the factory object of this class.
Example 12-26
The FactoryObject method is helpful when if the class of an object is not known. If the class is known, you can access the methods of a factory object as follows:
INVOKE CLASSNAME "XYFACTORYMETHODNAME"
Even if the class of an object is unknown, one of its factory methods can still be called as follows:
INVOKE OBJECTA "FACTORYOBJECT" RETURNING FACTORYOBJECTN
INVOKE FACTORYOBJECTN "XYFACTORYMETHODNAME"