Size: 627
Comment:
|
Size: 254
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 3: | Line 3: |
= Singleton = | = Pattern Programming = |
Line 5: | Line 5: |
=== classmethod === ---- ''' pro ''' |
See also http://dales.rmplc.co.uk/Duncan/accu/pythonpatterns.html/ |
Line 9: | Line 7: |
You can use both as simple class or as a singleton... | and http://www.thinkware.se/cgi-bin/thinki.cgi/PythonPatterns |
Line 11: | Line 9: |
---- ''' cons ''' |
=== GoF === |
Line 14: | Line 11: |
{{{ #!python # Code is Public Domain. class Singleton: _singleton = None def getSingleton(cls): if not Singleton._singleton: Singleton._singleton = cls() return Singleton._singleton getSingleton = classmethod(getSingleton) class Test(Singleton): def test(self): print self.__class__,id(self) t1 = Test.getSingleton() t2 = Test.getSingleton() t1.test() t2.test() }}} |
* SingletonProgramming * ProxyProgramming |
Pattern Programming
See also http://dales.rmplc.co.uk/Duncan/accu/pythonpatterns.html/
and http://www.thinkware.se/cgi-bin/thinki.cgi/PythonPatterns