Singleton vs. static preference and defect

When we want to deploy a web application, should we use a singleton Object or use a Static instead? What is the bottleneck for using each of them? I should know about memory issue, Concurrency problem and ....

PS: what happens for a class that was just readable (should use static or Singleton)

PS 2: what happens for a class that was readable and writable

+5
source share
2 answers

In the end, singleton / static methods will work in your case. I take this in both cases, your helper methods are clean and don't use or don't need any state. In the end, using singleton, you get several additional options, such as the possibility of falsification. With the help of a class, rather than static assistants, it is possible to develop a design or, possibly, replace another strategy, etc. In future. With static helpers you are almost stuck.

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

+3
source

Static: , - . .

Singleton: . .

+2

All Articles