Singleton class vs. class with static member

后端 未结 2 998
星月不相逢
星月不相逢 2021-02-02 01:54

Despite the many threads on that topic, I am still unclear as to when to choose which approach. I am hoping that by discussing a specific example, I will finally \"get it.\"

2条回答
  •  囚心锁ツ
    2021-02-02 02:49

    Singleton is a design pattern , Static is a C# keyword to make objects global.

    Singleton = Static + Thread safety + Lazy loading + Iterator pattern

    This is a nice presentation where the difference is explained with a sample code. https://www.youtube.com/watch?v=csQdTkEdhME

提交回复
热议问题