Changeset 83
- Timestamp:
- 08/23/07 20:50:10 (1 year ago)
- Files:
-
- branches/spike-20070613 tubes/tubes.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/spike-20070613 tubes/tubes.py
r81 r83 112 112 113 113 class Singleton(object): 114 """An implementation of the Singleton pattern. When a new Singleton is created, it first checks to see if an instance of its particular class exists. If not, then a new instance is created. After the created or stored instance is returned. The Singleton is designed so that subclasses of Singleton inherit this ability thereby leaving only the implmentation work for the subclass. 114 """An implementation of the Singleton pattern. When a new Singleton is 115 created, it first checks to see if an instance of its particular class 116 exists. If not, then a new instance is created. Afterwards the created or 117 stored instance is returned. The Singleton is designed so that subclasses 118 of Singleton inherit this ability thereby leaving only the implmentation 119 work for the subclass. 115 120 116 121 >>> class Test(Singleton): … … 131 136 132 137 def __new__(cls, *args, **kwargs): 133 """Overrides default object creation to ensure that only one instance per class is ever returned. These instances are stored in a dictionary on the Singleton class that is keyed on the type of the object being created.""" 138 """Overrides default object creation to ensure that only one instance 139 per class is ever returned. These instances are stored in a dictionary 140 on the Singleton class that is keyed on the type of the object being 141 created.""" 134 142 if not Singleton.__singletons.has_key(cls): 135 143 Singleton.__singletons[cls] = None
