Differences between revisions 1 and 19 (spanning 18 versions)
Revision 1 as of 2003-11-17 22:06:36
Size: 627
Editor: yermat
Comment:
Revision 19 as of 2004-04-14 09:55:23
Size: 381
Editor: mirville
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/ Patterns in Python by Duncan Booth]
Line 9: Line 8:
You can use both as simple class or as a singleton...  * Wiki:DesignPatternsBook
 * Thinki:PythonPatterns
Line 11: Line 11:
----
''' cons '''
=== GoF ===
Line 14: Line 13:
 * SingletonProgramming
 * ProxyProgramming
Line 15: Line 16:

{{{
#!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()
}}}
=== Other ===
 
 * DelegationEventModel
 * StateProgramming
 * EnumerationProgramming

PatternProgramming (last edited 2008-11-15 13:59:47 by localhost)

Unable to edit the page? See the FrontPage for instructions.