Why use singleton instead of static class?

前端 未结 7 728
迷失自我
迷失自我 2020-12-08 04:02

When would a singleton actually be easier or better than a static class? It seems to me creating a singleton is just extra effort that\'s not actually needed, but I\'m sure

7条回答
  •  粉色の甜心
    2020-12-08 04:50

    In many languages static classes lack useful features, like inheritance (and polymorphism more generally).

    (Not that I'm advocating singletons.)

提交回复
热议问题