Re: Static versus Singleton versus seperate Instantiations...

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: David Markle (N05P_at_Mdmarkle@gmail.com)
Date: 11/21/04


Date: Sun, 21 Nov 2004 13:05:40 -0500

Dan:

Good question. Use public (or internal) static methods instead of a
Singleton. Singletons would be the choice if you had a class that actually
needed to sit around in memory and maintain the state of something (for
example, if you wanted something to act kind of like an in-process "server".

-Dave

"Dan Bass" <danielbass [at] postmaster [dot] co [dot] uk> wrote in message
news:OcanFukzEHA.824@TK2MSFTNGP11.phx.gbl...
> while working in a probject, you realise that some string handling stuff
> you're implementing has occurred before in the same project. So being a
> good developer, you factorise the commonalities out and into some
> "StringMethods" type class...
>
> Would you:
> - create this object and use that instance each time to access the methods
> you need
> - use a singleton structure, so that only one instance is ever created
> - use public statics, so that you never need to create a host instance in
> the first place
>
> Would the same principle apply to global constants?
>
> I've been using public statics since the move to c# and wondered if this
> was the best approach.
>
> Thanks for your time.
>
> Daniel.
>


Quantcast