Re: Singletons
- From: "Alvin Ryder" <alvin321@xxxxxxxxxxx>
- Date: 17 Jul 2006 17:05:59 -0700
Sasa wrote:
Hi,
What would in your opinion be the justified case for singletons?
I have seen (and written :-( ) code which relies far too heavily on
singletons and this cannot bring anything good. At this point in time,
I'm somewhat on the other extreme - I'm not sure at all if singleton is
good idea in any situation.
Which examples would you provide as appropriate for singletons?
Regards,
Sasa
I agree singletons and statics get used wrongly, I know I did.
Nevermind singletons, even statics can become a problem, now I prefer
to pass everything around, its more work but it's also more flexible.
The only 3 legit. singleton cases I've come across are:- 1) JNDI single
point of call, 2) Sequential PrimaryKey generator for use with
databases, 3) Game engines
1 and 2 must be singletons across all machines, all processes, all JVMs
.... Interestingly the simple GoF mechanism that uses statics and
private contructors will not work in these very cases that actually
need to be true singletons!
3. "Games". You can only have one game running per graphics context
(card).
Cheers.
.
- References:
- Singletons
- From: Sasa
- Singletons
- Prev by Date: Re: More buzz wanted
- Next by Date: Re: Observer pattern limitations
- Previous by thread: Re: Singletons
- Next by thread: Re: Testing relational databases
- Index(es):
Relevant Pages
|