Re: Diff. between singleton class and static class
Jeff Louie <jeff_louie@yah oo.com> wrote:[color=blue][color=green]
> >It allows the singleton to be a subclass of something else. The normal[/color]
> 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.<
>
> Hmm. I don't understand why this is messy. In C# an interface can be
> looked at as subclassing where a concrete class implements an
> interface or extends a pure virtual class. The singleton GetInstance
> method can return an interface type or a method can take a singleton
> reference of an interface type allowing you to program to an
> interface. The supplier supplies a single instance of an object that
> implements the contract, the interface.[/color]
See my reply to Ignacio - the normal singleton pattern is very elegant
in enforcing a single instance without ever having to actually check in
a constructor that it hasn't been constructed before, etc. With
subclassing some of that elegance goes away.
--
Jon Skeet - <skeet@pobox.co m>
If replying to the group, please do not mail me too
Jeff Louie <jeff_louie@yah oo.com> wrote:[color=blue][color=green]
> >It allows the singleton to be a subclass of something else. The normal[/color]
> 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.<
>
> Hmm. I don't understand why this is messy. In C# an interface can be
> looked at as subclassing where a concrete class implements an
> interface or extends a pure virtual class. The singleton GetInstance
> method can return an interface type or a method can take a singleton
> reference of an interface type allowing you to program to an
> interface. The supplier supplies a single instance of an object that
> implements the contract, the interface.[/color]
See my reply to Ignacio - the normal singleton pattern is very elegant
in enforcing a single instance without ever having to actually check in
a constructor that it hasn't been constructed before, etc. With
subclassing some of that elegance goes away.
--
Jon Skeet - <skeet@pobox.co m>
If replying to the group, please do not mail me too
Comment