GofPatterns Gofpatterns  





Singleton Pattern   «Prev  Next»
Lesson 10 Singleton: related patterns
ObjectiveHow other Patterns work with or substitute for Singleton Patterns

How other Patterns work with or substitute for Singleton Patterns?

Patterns do not exist in a vacuum any more than classes or objects do. Most significant object-oriented systems designed with patterns use more than one.
The Singleton pattern prevents objects from being created, specifically objects of its class other than the one unique instance. Most other creational patterns actually create many different objects of some class. You can think of these creational patterns as machines cranking out objects on an assembly line.

However, the analogy only stretches so far. In particular, two machines do not create objects any faster than one machine. Therefore, it is common (though not required) to implement various creational patterns with Singleton patterns.
In particular, the
  1. Abstract Factory,
  2. Builder, and
  3. Prototype patterns
are often implemented with Singleton classes.
In the course project you will also encounter an example of part of a behavioral pattern, Observer, implemented as a Singleton.