Singleton class

The singleton design pattern allows to have one and only one instance of an object to be created within the whole application.

Singleton class

--Ads--

Singleton class

     

Singleton Design Pattern:

The singleton design pattern allows to have one and only one instance of an object to be created within the whole application. This can be achieved in java by making a Singleton  class

Benefits: 
Singleton pattern provides 
-- access only to the unique instances,
-- permits a variable number of instances, 
-- provides more flexibility than class operations. 
-- it reduces name space, and 
-- allows refinement of operations and representations, 

Usage: 
-- It is used only at those places where the user requires only one instance of a class to be operating through out the application. 
-- It is mostly used in the multi-threaded environments.
-- They often work as global variables permitting the allocation and initialization whenever required. 

Read more at:

www.roseindia.net/java/beginners/SingletonPattern.shtml