ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Mohd shahnawaz khan , Associate Project , Cognizant Technology Solution
تاريخ النشر: 2014/04/23
Mudassar Hakim
من قبل 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
من قبل 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. 

المزيد من الأسئلة المماثلة