Extending Python with C++ singleton pattern using boost pytho n lib

Delaney, Timothy tdelaney at avaya.com
Wed Apr 25 20:35:26 EDT 2001


> > a *very* useful design pattern, whilst *public* Singleton 
> is incredibly
> > difficult to enforce. You are best to have a private 
> Singleton (i.e. it is
> > only visible to your code) and expose its interface via a Flyweight.
> 
> ...and then there is no need for the Singleton Design Pattern -- just
> instance the 'whatever' only once, it IS your code so that 
> ain't hard:-).

Precisely - this is in essence the Singleton pattern, taken to its most
basic level (there is and will ever be only one instance of the class), but
doesn't require any of the baggage usually associated with the Singleton
design pattern. It's still worthwhile calling it a "Singleton" (because it
is), but no one else needs to know that. "Singleton" is a useful label so
long as people understand that it means there is one and only one instance,
not that "we've got all this code to attempt to prevent you from
instantiating it again, although in some cases it doesn't quite work, so
don't do that" ...

Tim Delaney




More information about the Python-list mailing list