How to instantiate a Singleton multiple times?

后端 未结 9 1865
醉酒成梦
醉酒成梦 2020-12-19 04:08

I need a singleton in my code. I implemented it in Java and it works well. The reason I did it, is to ensure that in a mulitple environment, there is only one instance of th

9条回答
  •  离开以前
    2020-12-19 04:55

    I feel compelled to post this series of articles about how Singletons destroy testability and are poor design choices:

    • Singletons are Pathological Liars
    • Where Have All the Singletons Gone?
    • Root Cause of Singletons

    Short summary: combining logic for what a class does with how it is instantiated makes code that is ugly to test, and should be avoided.

提交回复
热议问题