Purpose of singletons in programming

后端 未结 9 1590
傲寒
傲寒 2020-12-08 01:49

This is admittedly a rather loose question. My current understanding of singletons is that they are a class that you set up in such a way that only one instance is ever crea

9条回答
  •  囚心锁ツ
    2020-12-08 02:22

    Not all languages have "static classes" (for example C++ doesn't have them).

    Again with the C++ example, adding static variables to a class is a pain because you need to put them in both the header and the .cpp file, so a singleton in that case is very useful.

    Every language is different. I guess in C# they are not very useful (and in fact, from what I know, they are not used very often)

提交回复
热议问题