GofPatterns Gofpatterns  





Design Patterns  «Prev  Next»
Lesson 6Singleton: participants and collaborations
ObjectiveClasses comprise a Singleton and Clients interface with Singleton.

Classes comprise a Singleton and Clients interface with Singleton

The Singleton is a particularly simple pattern because it only has one class and two responsibilities. Thus, its participant list looks like this:
  1. Singleton
  2. Create the unique instance
  3. Provide a reference or pointer to that instance
Most patterns have much larger participant lists.


Collaborations
Singleton is such a simple pattern that it really does not say much about collaborations. Its collaborations list looks like this:
  1. Clients use the getInstance() method to get a pointer or reference to the unique instance of the Singleton.
A client is any object or class outside the pattern; generally one that only knows about the public interface that the pattern and its classes present, rather than about its private implementation.