OA. free
Free
Fujitsu System Design & Oop System Design & Oop Medium

Singleton Design Pattern Global Instance Control G)+ Which software design pattern is used...

Fujitsu technical mcq question, verified with a worked answer. Free to practise - no sign-up.

Singleton Design Pattern Global Instance Control G)+ Which software design pattern is used to ensure that a class has only one instance and provides a global point of access to that instance? AP - A) Factory Method - B) Singleton - C) Observer - D) Prototype

Choose one option.
Show answer & explanation
Answer: B. Singleton

The Singleton pattern is specifically designed to restrict the instantiation of a class to one single object and provide a global access point to that instance, ensuring consistency across the system.

Step-by-step Derivation:
Step 1: Analyze the requirements provided in the question: (a) Ensure a class has only one instance, and (b) Provide a global point of access.
Step 2: Evaluate Option A (Factory Method): This is a creational pattern used to create objects without specifying the exact class of object that will be created; it does not restrict the number of instances.
Step 3: Evaluate Option B (Singleton): This pattern implements a private constructor and a static method (e.g., getInstance()) that returns the unique instance of the class, satisfying both requirements.
Step 4: Evaluate Option C (Observer): This is a behavioral pattern used to notify multiple objects about state changes in another object; it does not control instance count.
Step 5: Evaluate Option D (Prototype): This is a creational pattern used to create new objects by copying an existing object (cloning); it explicitly creates multiple instances.
Step 6: Conclusion: Only the Singleton pattern matches the definition provided.