Singleton in go

后端 未结 9 2042
心在旅途
心在旅途 2021-01-30 10:46

How does one implement the Singleton design pattern in the go programming language?

9条回答
  •  旧时难觅i
    2021-01-30 11:08

    Before trying to find a way to bend Go to your will, you might want to take a look at some articles:

    • SINGLETON - the anti-pattern!

    • Singletons are Pathological Liars

    • Root Cause of Singletons.

    In summary, over time people have found singletons to be less than optimal, and imho especially if you are trying to do any test-driven development: on many levels they are pretty much as bad as global variables.

    [disclaimer: I know its not a strict answer to your question but it really is relevant]

提交回复
热议问题