SOFTWARE DESIGN
DESIGN PATTERNS
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
Structural Pattern
|
|
Behavioral Pattern
|
|
Creation Pattern
|
|
None of the above
|
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. Early Instantiation: creation of instance at load time.
Detailed explanation-2: -There are two types of singleton implementations: eager and lazy initialization. They differ in the way they initialize the singleton instance. We must also consider thread-safety in each of them.
Detailed explanation-3: -A singleton pattern ensures that you always get back the same instance of whatever type you are retrieving, whereas the factory pattern generally gives you a different instance of each type. The purpose of the singleton is where you want all calls to go through the same instance.