Re: Diff. between singleton class and static class
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Thu, 2 Jun 2005 07:20:32 +0100
Jeff Louie <jeff_louie@xxxxxxxxx> wrote:
> First, the Singleton Pattern generally creates a single instance of a
> class, but this is not absolute. In fact, you can argue that some of
> the flexibility of the Singleton Pattern is that it allows you the
> programmer to return more than one instance of a class at a later
> date without breaking the client code.
I'd argue that in that case it's a factory. Certainly the GoF book
defines a singleton in terms of only providing one instance. I agree
that using a singleton allows you to change it into a factory at a
later date without breaking client code though. (Assuming the client
code isn't relying on it being a singleton.)
<snip>
> There _are_ advantages to the Singleton pattern and they include:
<snip>
> 3) Allows sub-classing.
It allows the singleton to be a subclass of something else. The normal
patterns that ensure that only a single instance is ever created don't
work well with subclasses. It can be done, but it's somewhat messy.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.
- Follow-Ups:
- Re: Diff. between singleton class and static class
- From: Jeff Louie
- Re: Diff. between singleton class and static class
- From: Ignacio Machin \( .NET/ C# MVP \)
- Re: Diff. between singleton class and static class
- References:
- Diff. between singleton class and static class
- From: DBA
- Re: Diff. between singleton class and static class
- From: Jeff Louie
- Diff. between singleton class and static class
- Prev by Date: RE: SQL Connection Error.......how to come out?
- Next by Date: Re: Fast string operations
- Previous by thread: Re: Diff. between singleton class and static class
- Next by thread: Re: Diff. between singleton class and static class
- Index(es):
Relevant Pages
|