15.singleton Pattern On ABAP Objects
15.singleton Pattern On ABAP Objects
Working with singleton design patterns in Object oriented ABAP, Singleton class
in OOABAP
+ -
Sometimes in the real-time business scenarios, we need to have only one instance for a class at a
point of time, for this one we have the concept of singleton in ABAP objects.
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.
Learner Questions
No Questions by learners, be first one to ask ..!!
+ -
Follow below steps to create singleton class in Object oriented ABAP
Go to methods tab, add a static method INSTANTIATE and click on parameters button .
Add a returning parameter as below.
Go back to methods, double click on method INSTANTIATE and add below code.
METHOD INSTANTIATE.
ENDMETHOD.
Save and activate the class, go to SE38, create a program 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.
Learner Questions
+ -
Below is the example of local singleton class in Object Oriented ABAP Programming .
REPORT ZSAPN_SINGLETON_CLASS.
ENDCLASS.
Learner Questions