SOFTWARE DESIGN
DESIGN PATTERNS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
Ensures a class has only one instance and provides a global point of access to it
|
|
Ensures a class has only one instance for every class it uses it.
|
|
Ensures a class has only one instance per method
|
|
Ensures a class has only one instance as final.
|
Detailed explanation-1: -Singleton Pattern says that just"define a class that has only one instance and provides a global point of access to it". In other words, a class must ensure that only single instance should be created and single object can be used by all other classes.
Detailed explanation-2: -1)Private constructor to restrict instantiation of the class from other classes. 2)Private static variable of the same class that is the only instance of the class. 3)Public static method that returns the instance of the class, this is the global access point for outer world to get the instance of the singleton class.
Detailed explanation-3: -The Singleton Design Pattern is a Creational pattern, whose objective is to create only one instance of a class and to provide only one global access point to that object.
Detailed explanation-4: -Q 1-Which of the following describes the Singleton pattern correctly? A-This pattern creates object without exposing the creation logic to the client and refer to newly created object using a common interface.