no singletons, please (was Re: an example Re: Connecting to running win32com server)

Alex Martelli aleaxit at yahoo.com
Thu Oct 12 05:33:11 EDT 2000


"Mark Hammond" <MarkH at ActiveState.com> wrote in message
news:pJ6F5.16918$aD2.74639 at news-server.bigpond.net.au...
    [snip]
> > Here's a test you can try.  Go to the win32com/servers
> > directory and copy, for example, dictionary.py to a file
> > named shareddictionary.py in the same directory.  Then,
    [snip]
> FWIW, this is also how I recommend implementing "singletons" in
> pythoncom - basically you create a single Python instance that does
> the real work - your multiple COM objects simply delegate to the real
> Python object.  So although you technically still have multiple COM
> objects floating around, they all reference the same "real object"
> doing the work.

Although we seem to be in violent agreement, I think this
bears repeating, because the "Singleton" pattern is so snively
seductive, yet often inappropriate...:

it's often best to *decouple identity and state*, by having
many objects (different identities) *sharing state*, rather
than trying to ensure the state-sharing happens through all
object being one (having the same identity).

This applies to COM (in any language), but also outside of it.

"Same-Identity" can be a heavy burden to carry around when
all one really wants to ensure is "Same-State"... which is
most of the time when one starts thinking "Singleton"!


Alex






More information about the Python-list mailing list