Most common examples of misuse of singleton class

后端 未结 11 1010
伪装坚强ぢ
伪装坚强ぢ 2020-12-16 00:19

When should you NOT use a singleton class although it might be very tempting to do so? It would be very nice if we had a list of most common instances of \'singletonitis\' t

11条回答
  •  难免孤独
    2020-12-16 01:11

    Singletons are virtually always a bad idea and generally useless/redundant since they are just a very limited simplification of a decent pattern.

    Look up how Dependency Injection works. It solves the same problems, but in a much more useful way--in fact, you find it applies to many more parts of your design.

    Although you can find DI libraries out there, you can also roll a basic one yourself, it's pretty easy.

提交回复
热议问题