Recall & Review
beginner
What is the Singleton pattern?
The Singleton pattern ensures a class has only one instance and provides a global point of access to it.Click to reveal answer
beginner
Why use the Singleton pattern in system design?
To control resource usage by limiting the number of instances, and to provide a single shared object accessible globally.
Click to reveal answer
intermediate
How does the Singleton pattern prevent multiple instances?
By making the constructor private and providing a static method that returns the single instance, creating it only once.
Click to reveal answer
intermediate
What is a common problem with Singleton in multithreaded environments?
Multiple threads may create multiple instances if access is not synchronized properly, breaking the Singleton guarantee.
Click to reveal answer
intermediate
Name one way to make Singleton thread-safe.
Use synchronized access or double-checked locking to ensure only one instance is created even with multiple threads.
Click to reveal answer
What does the Singleton pattern guarantee?
✗ Incorrect
Singleton ensures only one instance of a class exists and provides global access to it.
How is the Singleton instance usually accessed?
✗ Incorrect
Singleton provides a public static method to get the single instance.
What problem can occur if Singleton is not thread-safe?
✗ Incorrect
Without thread safety, multiple threads can create multiple instances, breaking the Singleton pattern.
Which of these is NOT a typical Singleton feature?
✗ Incorrect
Singleton uses a private constructor to prevent multiple instances, so multiple public constructors are not allowed.
Which technique helps make Singleton thread-safe?
✗ Incorrect
Double-checked locking ensures only one instance is created even with multiple threads.
Explain the Singleton pattern and why it is useful in system design.
Think about how you would share one resource safely across a system.
You got /4 concepts.
Describe how to implement a thread-safe Singleton.
Consider what happens when multiple threads try to create the instance at the same time.
You got /4 concepts.