Next / Previous / Contents / Shipman's homepage

46.2. class Singleton

singleton.py
# - - - - -   c l a s s   S i n g l e t o n

class Singleton(object):
    '''Base class for singleton objects.

      State/Invariants:
        Singleton.__classMap:
          [ a dictionary whose keys are the classes
            instantiated so far, and each related value
            is the single instance of that class ]
    '''

This class can manage any number of different derived classes. A class variable, .__classMap, is used to keep track of their instances.

singleton.py
    __classMap = {}