views:

215

answers:

3

Hi, When we want deploy Web Application should we use singleton Object or use Static instead of? what is the bottleneck for use each of them? I should know about Memory Problem , Concurrency problem and ... .

P.S: what happen for the class that was just readable (should use static or Singleton)

P.S 2: what happen for the class that was readable and writable

+2  A: 

Static: A single instance shared among all threads - any access to the static member will return the same instance. There are no restrictions on creating other instances of the same type.

Singleton: A single instance for the entire application. No other instances of this type can be created within the application.

Andrew Hare
An "all static" class is strange. There's no "thing" represented by an instance of the class. If there's no "thing", why have a class definition in the first place?
S.Lott
I meant "static instance" not "all static class". An all static class does have some usage though for organizational purposes.
Andrew Hare
+1  A: 

In the end it appears in your case a singleton / static methods would both work. I take it in both cases your helper methods are pure and do not use or need any state. In the end using a singleton gives you a few extra options such as the possibility to mock. By using a class rather than static helpers the possibility exists to evolve the design or perhaps substitute a different strategy etc some time in the future. With static helpers your pretty much stuck.

Since your methods are pure concurrency will not and cannot be a problem as no state is shared.

mP
that's right, but if use static method in my web application is it possible I encounter problem later?some where I read it's better don't use static in web application.
Am1rr3zA
A: 

http://dotnetperls.com/singleton-static

MichaelT
I wan t in Java(if has any dif with C#)
Am1rr3zA