Singleton Class
Singleton Class
Singleton pattern: is the one of the simplest design patterns which involves only one
class which instantiates itself to make sure that it creates one instance. Singleton
ensues that it has only one instance and provides global point of access to the object.
Example - Logger Classes
The Singleton pattern is used in the design of logger classes. These classes are usually
implemented as singletons, and provide a global logging access point in all the
application components without being necessary to create an object each time a logging
operation is performed.
Follow below steps to create singleton class in Object oriented ABAP
Step 1: Create a private class in Se24
Go to SE24, provide name as ZSAPN_CL_SINGLETON and click on create.
Go to methods tab, add a static method INSTANTIATE and click on parameters button.
METHOD INSTANTIATE.
ENDMETHOD.
REPORT ZSAPN_SINGLETON_GLOBAL.
REPORT ZSAPN_SINGLETON_GLOBAL.
DATA : LO_CLASS TYPE REF TO ZCL_SAPN_SINGLETON.
LO_CLASS = ZCL_SAPN_SINGLETON=>INSTANTIATE( ).
Now you can access all public instance components through the object.