Tuesday, May 29, 2012

Design Pattern - Singleton

http://en.wikipedia.org/wiki/Singleton_pattern

Intent:
  1. Ensure that a class has one and only one instance, and provide a global point of access to the instance
Applicability:
  1. Exactly N instance(s) of a class needed:
    1. must be accessible to clients
    2. a well-known access point
  2. When class of sole instance should be extensible
Structure:


Participants:
  1. Singleton defines an Instance operation that lets clients access its unique instance.
  2. Instance is a class operation (e.e. static member funciton in C++).
  3. May be responsible for creating its own unique instance.
Overview:
Client accss a Singleton instance solely through Singleton's instance operation
  1. Controlled access to sole instance.
  2. Reduced name space.
  3. Permoits refinement of operations and representation.
  4. Permits a variable number of instances.
  5. More flexible than class operations.
Applications:
  1. Settings
  2. Configuration Data
  3. Read-only Data / Cache
  4. Print spooler

No comments: