Why should i use python if i can use java
Don Dwiggins
dwig at advancedmp.net
Thu Jun 7 12:49:36 EDT 2001
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.
(I suppose I should mention that I've only used the pattern once, in a C++
program, to hold a transformed version of the parameter list to the program.
It seemed like a reasonable usage -- although I didn't need subclassing --
since the various parameters were accessed in a variety of places in the
code, and needed some interpretation, validation, and processing before
use. In Smalltalk I probably would have used a class that was never
instantiated -- a "system-supplied" singleton.)
--
Don Dwiggins "Solvitur Ambulando"
Advanced MP Technology
dwig at advancedmp.net
More information about the Python-list
mailing list