Why should i use python if i can use java
dsh8290 at rit.edu
Thu Jun 7 13:26:36 EDT 2001
On Thu, Jun 07, 2001 at 09:49:36AM -0700, Don Dwiggins wrote:
| Alex Martelli quotes Glyph Lefkowitz:
| >> > an elegant way of implementing singletons (or does it? anyone?)
| >> Aah, the singleton. Global variables for the new millennium. First of
| >> all, the singleton "pattern" is usually a bad idea. If you have a class
| > *AMEN, HALLELUJAH*! This makes two of us sharing this dislike
| > for the Singleton Design Pattern, so I'm not a Singleton any
| > more -- see, that's one typical issue with Singleton DP, what
| > starts out as a singleton often becomes not one:-).
| According to the GOF "Applicability" section on Singleton:
| Use the Singleton pattern when
| - there must be exactly one instance of a class, and it must be
| accessible to clients from a well-known access point.
| - when the sole instance should be extensible by subclassing, and
| clients should be able to use an extended instance without modifying
| their code.
| If you take the whole description of the Singleton pattern seriously, to say
| that you "hate" the pattern would seem to mean that you don't believe that
| programs should ever need something that satisfies these criteria. Is that
| true for both of you? Whether it is or not, I'd like to hear a bit more
| explanation for the strong emotional reaction to the pattern.
Alex Martelli discussed his views with me a couple months ago. He
explained that flyweight proxies can serve the same need as a
singleton, but without the subtle problems the Single DP can present.
The flyweight proxies don't hold any state of their own, but rather
delegate everything to the single instance of a private class. The
proxies can be copied around, instantiated at will, etc. They are
"normal" objects. This issue is especially important in C++ where the
compiler can automatically create and call a copy constructor for your
This is a very brief summary of what Alex showed me. I'm sure he will
see your question and give you the long, detailed, explanation he is
so skilled at :-).
More information about the Python-list