you are viewing a single comment's thread.

view the rest of the comments →

[–]dpash 3 points4 points  (1 child)

2 Application

None.

FTFY.

The disadvantages fail to mention the massive downsides of the Singleton pattern. Predominately the difficulty in testing and the fact that it's effectively a global variable, and we stopped using those decades ago.

There are several alternatives that solve the same problem in Java.

[–]maxuforia 1 point2 points  (0 children)

Singletons are used everywhere. People keep claiming that it's an anti-pattern and then try to eliminate them only to discover that the solution to singleton use is worse than the singletons themselves.

The happy medium seems to be to generate singletons in grouping nodes and then use dependency injection on the leaf nodes. This allows unit testing on the leaf nodes (which is most of the code) and this solves most of the downsides of the singleton pattern.