Singleton Pattern   «Prev  Next»
Lesson 5 Singleton Design Pattern Structure
ObjectiveStudy the structure of the Singleton.

Singleton Design Pattern Structure

Here is a diagram showing the structure of the Singleton pattern.
The pattern of the Singleton is a relatively simple pattern, therefore its diagram is relatively simple.

  1. This diagram says that the Singleton pattern consists of a single class. This class takes the role of the Singleton in the operation
  2. This class has a single field called theInstance which points to the object that is the unique instance.
  3. The Singleton class has two methods, a static getInstance() method that returns a pointer or reference to the unique instance and a protected constructor.
Singleton Design Structure
None of the names here are important. In general, the names of the methods, fields, and classes change in each different implementation. What is important is the relationships between the different parts, and the roles each part plays in the whole pattern.
You should also note that the entire class is not diagrammed here, only the parts relevant to the pattern. For instance, it is almost certain that the class has some other methods and fields. If it's an AudioDevice class discussed in the motivation, it probably has some sort of play() methods for example. However, these are not part of the pattern itself.

Singleton Pattern - Quiz

Click the link below to take a short quiz on the material that was just covered.
Singleton Pattern - Quiz