Intent

One instance of a class or one value accessible globally in an application.

Where to use & benefits

Structure


Participants

Singleton  (ShapeContainerFullState, ShapeContainerEmptyState, ShapeContainerFullState)
defines an Instance operation that lets clients access its unique instance. Instance is a class operation and responsible for creating and maintaining its own unique instance

Example

In the demonstration application, that shape container states (ShapeContainerFullState, ShapeContainerEmptyState and ShapeContainerPartialState) are modeled as singleton object. Here the singleton feature is achieved by making the constructor as private and providing the static method to create/return the object.

Class Diagram


Source Code Links