Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Which classes are candidates of Singleton? Which kind of class do you make Singleton in Java?

user-image
Question ajoutée par Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
Date de publication: 2014/04/23
Mudassar Hakim
par Mudassar Hakim , Requirement Analyst & Software Developer , L&T Infotech

Candidates for singleton will be those classes which can be instantiated only once no matter how many times you call the instantiation process so that later when called again it return created instance rather than the a new instance.

Examples of Singleton classes could be your database connection object,, Principal object which is used for security

The decision for making a particular class as singleton is a design/architectural decision (and hence the name 'Singleton design pattern'). Most of the cases you make a class singleton becuase in the whole of the application (the JVM) you need a single source of information of a particular sort; or it could be that only one object can exist theoretically.

Yassine Sabi
par Yassine Sabi , Software Engineer , Capgemini

Most of the time, I use Singleton when it comes to sessions it needs to be instancied only once so every user has it's own session. 

More Questions Like This