Bird
Raised Fist0

Which design pattern ensures a class has only one instance and provides a global point of access, while also delaying instance creation until it is first needed with thread safety?

easy💻 Programming Q1 of Q15
OOP & Design Patterns - Singleton Pattern - Thread Safety, Double-Checked Locking & Lazy Init
Which design pattern ensures a class has only one instance and provides a global point of access, while also delaying instance creation until it is first needed with thread safety?
AThread-safe Lazy Singleton Pattern
BFactory Pattern
CObserver Pattern
DPrototype Pattern
Step-by-Step Solution
Solution:
  1. Step 1: Understand Singleton Pattern

    The Singleton pattern restricts instantiation of a class to one object and provides a global access point.
  2. Step 2: Lazy Initialization

    Lazy initialization means the instance is created only when first requested, not at class loading.
  3. Step 3: Thread Safety

    Thread safety ensures that multiple threads do not create multiple instances simultaneously.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Singleton + Lazy + Thread Safety = Thread-safe Lazy Singleton [OK]
Quick Trick: Singleton with lazy init and thread safety fits best [OK]
Common Mistakes:
MISTAKES
  • Confusing Factory with Singleton
  • Ignoring thread safety in lazy init
  • Choosing patterns unrelated to instance control
Trap Explanation:
PITFALL
  • Factory creates multiple instances; Observer and Prototype do not guarantee single instance.
Interviewer Note:
CONTEXT
  • Tests understanding of Singleton pattern with lazy initialization and thread safety.
Master "Singleton Pattern - Thread Safety, Double-Checked Locking & Lazy Init" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes