multi-instance and classic singleton design patterns

Paul McGuire ptmcg at austin.rr._bogus_.com
Wed Aug 18 18:17:07 EDT 2004


"Neil Zanella" <nzanella at cs.mun.ca> wrote in message
news:b68d2f19.0408181354.43821bd9 at posting.google.com...
> Hello,
>
> I would be very interested in knowing how the following C++ multi-instance
> singleton (AKA Borg) design pattern based code snippet can be neatly coded
> in Python. While there may be somewhat unusual places where multi-instance
> singleton is more useful than plain singleton, it seems to me that the
> former leads to less coding, so unless I can somehow package the
> singleton pattern in a superclass (so I don't have to code it
> explicityly in every singleton class I have), then I am more
> interested in the multi-instance singleton design pattern.
>
> Thanks,
>
> Neil
<snip C++ example code>

Neil -

You may be new to the Python community, given that you are porting a C++
pattern to Python.  There is a terrific resource for snippets of this kind
in the Python Cookbook, to be found at
http://aspn.activestate.com/ASPN/Cookbook/Python/ .

You should find a *very* neat implementation of this pattern at the bottom
of http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 .

-- Paul

(You can also try googling for "python singleton borg" to find this and many
other helpful suggestions and comments.)





More information about the Python-list mailing list