Singleton Consequences - Quiz Explanation

The correct answers are indicated below, along with text that explains the correct answers.
 
1. What kind of pattern is Singleton?
Please select the best answer.
  A. object creational
  B. object structural
  C. class behavioral
  D. class creational
  The correct answer is A.
Singleton is object creational. It is a creational pattern because it concerns itself with the creation of objects, more specifically with making sure more than one object is not created. It is an object pattern because it deals with the relationships between objects (specifically the unique instance object the class holds and other objects access) rather than with relations between classes and their subclasses.

2. The collaborations in a design pattern describe:
Please select the best answer.
  A. The classes that collaborate with one another to form the pattern
  B. How classes and objects outside the pattern interact with the pattern
  C. How functions in the pattern invoke other functions in the pattern
  D. How methods in the pattern invoke other methods in the pattern
  The correct answer is B.
Remember, patterns (and collaborations) are described at the level of classes and objects, not methods or functions.

3. Which of the following is a consequence of the Singleton?
Please select the best answer.
  A. Pure static members lend themselves to subclassing
  B. Different subclasses can be configured randomly
  C. The Singleton object can be used by one object at a given time
  D. Access to the object is controlled
  The correct answer is D.
The Singleton class can easily control who accesses its single instance and how it is accessed. A is incorrect because pure static members do not lend themselves to subclasses. B is incorrect because subclasses can be chosen at runtime through polymorphism. C is incorrect because a Singleton pattern works with the instance methods and fields when the same object must be used in different objects at the same time.

4. A Singleton class would best be used to represent:
Please select the best answer.
  A. A parallel port
  B. A serial port
  C. A computer's audio device
  D. A monitor
  The correct answer is C.
It is certainly possible for modern computer hardware to have more than one serial port, parallel port, and even more than one monitor. A computer's audio device limits the output to one audio playback at a time.