Singleton in go

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

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

9条回答
  •  佛祖请我去吃肉
    2021-01-30 10:58

    Just have a single static, final, constant, global, application-wide instance of the Object you want.

    This however contradicts the OO paradigm. Its use should be limited to primitives and immutable objects, not to mutable objects.

提交回复
热议问题