Design Patterns    |     Security    |     Testing    |     Distributed Computing    |     Contact

Singleton Design Pattern, UML diagram, Java Example

             

Definition

Ensure a class only has one instance, and provide a global point of access to it.

Class Diagram

Builder

Participants

  • Singleton.
    • defines an Instance operation that lets clients access its unique instance.
    • responsible for creating and maintaining its own unique instance.

Benefits

  • Controlled access to unique instance.
  • Reduced name space.
  • Allows refinement of operations and representations.
  • Permits a variable number of instances.
  • More flexible than class operations.

Usage

  • When there must be only one instance of a class.