Singleton Pattern - Quiz Explanation

The correct answers are indicated below, along with brief explanations for why each answer is correct.
Return to Quiz
 
1. The general purpose of the Singleton pattern is to:
Please select the best answer.
  A. Ensure that no more than one instance of a class exists.
  B. Ensure that only one instance of a class exists at the same time.
  C. Separate objects in a single class from objects in another class.
  D. Control creation of objects in a single class or another class.
  The correct answer is A. A Singleton ensures there is exactly one instance within a runtime boundary (most commonly one process, one application container, or one classloader) and provides a controlled access point to that instance. It is not about separating objects across classes, and it is not a general-purpose factory for creating objects across multiple classes.

Modern clarification: “Singleton” does not mean “one instance across a distributed system.” If your application runs on multiple servers or multiple processes, each process can have its own Singleton instance.

2. The participants in a design pattern are:
Please select the best answer.
  A. The methods used in the pattern
  B. The other patterns that participate with the pattern
  C. The classes and objects used in the pattern
  D. The fields used in the pattern
  The correct answer is C.
In GoF terminology, the participants are the classes and/or objects that play roles in the pattern’s collaboration. Methods and fields matter, but they are discussed as parts of the participating classes and objects, not as participants by themselves.

3. The consequences of a design pattern are:
Please select the best answer.
  A. The pitfalls of using the particular pattern
  B. The results of choosing a pattern
  C. The time a program using the pattern takes to run
  D. The time it takes to design a program using the pattern
  The correct answer is B. Although the English word consequences can sound negative, in design patterns it refers to the major outcomes of using the pattern: tradeoffs, benefits, and liabilities. The best pattern choice is the one whose positive consequences outweigh the negative ones for your context.

4. Which of the following is specifically in the realm of applicability of the Singleton?
Please select the best answer.
  A. The class has only a single member method.
  B. The class has only a single field.
  C. The class should have exactly one instance.
  D. The class cannot be subclassed.
  The correct answer is C.
The “single” in Singleton refers to the number of instances, not the number of fields or methods. A Singleton class can still have many fields and many methods.

D is incorrect because a Singleton can be subclassed in some implementations (though many modern teams prefer composition over inheritance). The defining requirement is the single-instance constraint and controlled access—not whether inheritance is used.