Domanda di colloquio di ZE PowerGroup

What is a singleton?

Risposte di colloquio

Anonimo

8 nov 2017

A Singleton class has only one object that is returned by it. One would question it's use : It is a design pattern and used in frameworks like Spring MVC while loading the beans using the configuration metadata. The idea is outside of the Singleton class, whenever an object is created, it is the only object created. Obtaining an object is also through a static method (and not a constructor - as we declare a default private constructor for a singleton class to block new keyword-based object creation) which returns an instance of the class. If already created, it returns the initialized object.

Anonimo

8 nov 2017

A Singleton class has only one object that is returned by it. One would question its use : It is a design pattern and used in frameworks like Spring MVC while loading the beans using the configuration metadata. The idea is outside of the Singleton class, whenever an object is created, it is the only object created. Obtaining an object is also through a static method (and not a constructor - as we declare a default private constructor for a singleton class to block new keyword-based object creation) which returns an instance of the class. If already created, it returns the initialized object.