This is my singleton class in ABAP: CLASSzcl_jerry_singletonDEFINITIONPUBLICFINALCREATE PRIVATE.PUBLIC SECTION.INTERFACESif_serializable_object.CLASS-METHODSclass_constructor.CLASS-METHODSget_instanceRETURNINGVALUE(ro_instance)TYPE REF TOzcl_jerry_singleton.PROTECTED SECTION.PRIVATE SECTION.CLASS-DATAso_instanc...
Now I would like to share you an example of Singleton Pattern implemented in ABAP. Here a counter is made as a singleton object so that the counter can be incremented from anywhere and also making sure that only one counter exists. A class which implements Singleton Pattern should have the ...
--> Like method, you have to use CLASS-DATA that's all. The example: CLASS zcl_temp_singleton_001 DEFINITION PUBLIC FINAL CREATE PRIVATE . PUBLIC SECTION. CLASS-METHODS get_instance RETURNING VALUE(ro_instance) TYPE REF TO zcl_temp_singleton_001. METHODS set_data IMPORTING iv_valeur TYPE...
How to implement Singleton design Pattern in ABAP? We can use the CLASS-DATA(static data) to save the created instance within the class and check with that instance, if application asks for a new instance. We will look at this example. UML diagrm for the example: Code Snippet: *&---*...