[Tutor] singleton pattern

Benoit Dupire bdupire@seatech.fau.edu
Wed, 16 May 2001 12:17:44 -0400


D-Man wrote:

> On Wed, May 16, 2001 at 10:26:32AM -0400, Benoit Dupire wrote:
>
> The thing to remember about Python is that unlike Java you are not
> forced to put everything inside a class.  Somethings don't really
> belong inside a class.  Static methods are one of those things.  They
> belong in a module instead.  There is no way to have static methods in
> a class in python, but you have modules instead.
>

yep.. i think it's hard for me to get used to the idea, which means (IMHO)
combining 2 paradigms..
I think we already discussed that, not so long ago, in this mailing-list uh
? :o) !!
One day... i'll get used to this idea ...


>
>
> | Python unfortunately does not support overriding...
>
> It does.  It doesn't support overloading.

uuuuuuh!!! oops ! yes. That's what i meant...

>
>
> Here is an alternative to use if you are a fan of functions and would
> rather not use public module variables :

<snip>
plenty of choice !
<snip>
thanks a lot !
<snip!!>

Here is what i found in the Python mailing list, if you are a fan of
classes...(like me!)


class MySingleton:
        class _my_dummy: pass
        _dummy=_my_dummy()
        _initialized=0
        def __init__(self, ....):
                if initialized: return
                ......
        def __getattr__(self, attr):
                return _dummy.__dict__[attr]

        def __setattr__(self, attr, val):
                _dummy.__dict__[attr]=val


It's from Moshe, but yes! i'd rather combine my class with a function than
using this more complex solution.....

Thank your for all the replies....
--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?