On Nov 25, 1:55 pm, Arne Vajh?j <a...@vajhoej.dk> wrote:
Adi wrote:
I have a question about singleton pattern. In my java user group,
someone said that this pattern should be avoided, but he didn't explain
the reason.
So I am curious here, is this statement true ?
Someone else replied that this pattern is hard to test and make other
classes tightly coupled with this Singleton class. Somehow I doubt it
but I also can find any argument for that. What I know is just because
this pattern is hard to test doesn't mean that this pattern should be
avoided right ? I use this pattern a lot of times and found it useful.
Do you have any comments ?Singleton is a valid pattern.
Most of the criticism found on the net is ridiculous ("if you implement
it wrong then it will not work" type).
The only real problem I can think of is a modifiable singleton in a
clustered environment (or other multi JVM environment).
The Singleton is a valid pattern.
The Singleton is the most used pattern.
The Singleton is the most abused pattern (e.g. used mainly for finding
something at a well know location, rather than to enforce 'just one
instance')
See:
http://groups-beta.google.com/group/comp.object/browse_thread/thread/54abf37ca7b7abda/0539f2454634cfca?lnk=st&q=Singleton+Pattern&rnum=5#0539f2454634cfca
The majority of times, having a global access to something is the
usual reason for creating a Singleton. In these cases, its not a
singleton that was required, but a singleton containing mutliple items
- in other works a 'Container' or 'Toolbox'
a specific pattern is the best solution or not.
Singleton is probably the most widely abused. But no surprise if it
is the most widely used.
is usually not a bad solution either.
about singletons.