Singleton classes
Many resource classes, such as IccFile , can be used to create multiple resource objects within a single program.
IccFileId id1("File1");
IccFileId id2("File2");
IccFile file1(id1);
IccFile file2(id2);
However, some resource classes are designed to allow the programmer
to create only
one
instance of the class; these are called singleton
classes. The following Foundation Classes are singleton:
- IccAbendData provides information about task abends.
- IccConsole , or a derived class, represents the system console for operator messages.
- IccControl , or a derived class, such as IccUserControl , controls the executing program.
- IccStartRequestQ , or a derived class, allows the application program to start CICS® transactions (tasks) asynchronously.
- IccSystem , or a derived class, is the application view of the CICS system in which it is running.
- IccTask , or a derived class, represents the CICS task under which the executing program is running.
- IccTerminal , or a derived class, represents your task's terminal, provided that your principal facility is a 3270 terminal.
Any attempt to create more than one object of a singleton class results in an error – a C++ exception is thrown.
A class method,
instance
, is provided for each of these
singleton classes, which returns a pointer to the requested object and
creates
one if it does not already exist. For example:
IccControl* pControl = IccControl::instance();