‎2005 Mar 10 10:46 AM
‎2005 Mar 13 9:08 AM
program pattern_singleton.
***********************************************************************
* Singleton
* =========
* Intent
* ------
* Ensure a class has only one instance, and provide a global point
* of access to it.
***********************************************************************
class lcl_Singleton definition create private.
public section.
class-methods:
get_Instance returning value(Result) type ref to lcl_Singleton.
private section.
class-data:
fg_Singleton type ref to lcl_Singleton.
endclass.
class lcl_Singleton implementation.
method get_Instance.
if ( fg_Singleton is initial ).
create object fg_Singleton.
endif.
Result = fg_Singleton.
endmethod.
endclass.
‎2005 Mar 10 11:33 AM
Hello Vinay,
Could you specify what the context is ? A singleton class, as I understand, is the one which has only one instance per session.
Now, do you want to create one class? For what purpose?
Regards,
Anand Mandalika.
‎2005 Mar 10 11:41 AM
create a class with definition create private to make sure that no instance can be created from outside of the class.
define a static attribute wich holds the instance.
create the instance in a class method or in the class constructor and only if the static attribute is initial.
Christian
‎2005 Mar 13 9:08 AM
program pattern_singleton.
***********************************************************************
* Singleton
* =========
* Intent
* ------
* Ensure a class has only one instance, and provide a global point
* of access to it.
***********************************************************************
class lcl_Singleton definition create private.
public section.
class-methods:
get_Instance returning value(Result) type ref to lcl_Singleton.
private section.
class-data:
fg_Singleton type ref to lcl_Singleton.
endclass.
class lcl_Singleton implementation.
method get_Instance.
if ( fg_Singleton is initial ).
create object fg_Singleton.
endif.
Result = fg_Singleton.
endmethod.
endclass.
‎2005 Mar 14 3:58 AM