Generic singleton

mk mrkafk at gmail.com
Thu Mar 4 06:50:45 EST 2010


Steven D'Aprano wrote:
> Groan. What is it with the Singleton design pattern? It is one of the 
> least useful design patterns, and yet it's *everywhere* in Java and C++ 
> world.

It's useful when larking about in language internals for learning 
purposes, for instance. I don't recall ever actually having significant 
need for it.


>>      def __new__(cls, impclass, *args, **kwargs):
>>          impid = id(impclass)
> 
> Yuck. Why are you using the id of the class as the key, instead of the 
> class itself?

Bc I didn't know whether it was safe to do that: like Arnaud pointed 
out, the *type* of bultins is hashable.

Regards,
mk






More information about the Python-list mailing list