2006 Jul 10 12:06 PM
Hi,
1) I have created a class with its instantiation set to private.
2) Declared a static attribute 'instance' in the class with TYPE REF to same class.
3) In the class constructor checked if instance is initial if it is then created an object.
if instance initial.
creat'e object instance.
endif.
4) Created a method get_instance which exports the 'instance' attribute of the class.
I suppose this is fine for implementing the Singleton class.
Created a sample program where I call get_instance of this class.
Open two sessions of SE80 and execute this program in debug mode. I see that each program is executing the class constructor and instance is initial every time.
If instance is initial in each execution (with two parllel executions) then what is the purpose of declaring it as static.
Since its initial create object is executed every time in
each execution. Then the instance is not unique and its not singleton.
Can somebody explain signleton in ABAP. Why is it different from JAVA.
Regards,
Sesh
2006 Jul 12 9:43 AM
Hi Sesh,
Your class object exists per default once per session. As of release 6.40 you can create objects in the shared memory (with addition AREA HANDLE), thus session-independent! For that, you need to mark the class as shared-memory enabled. This should create a singleton as in Java.
Best regards,
Georg
2006 Jul 12 9:43 AM
Hi Sesh,
Your class object exists per default once per session. As of release 6.40 you can create objects in the shared memory (with addition AREA HANDLE), thus session-independent! For that, you need to mark the class as shared-memory enabled. This should create a singleton as in Java.
Best regards,
Georg
2006 Jul 12 10:48 AM
Hi Georg,
I am aware of the Shared Objects concept. What I was not aware was Singleton implementation model of java do not work in ABAP. Any way thanks for the reply. I am awarding you some points for the reply :-).
Regards,
Sesh