Most common examples of misuse of singleton class

后端 未结 11 976
伪装坚强ぢ
伪装坚强ぢ 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:19

    Well singletons for the most part are just making things static anyway. So you're either in effect making data global, and we all know global variables are bad or you're writing static methods and that's not very OO now is it?

    Here is a more detailed rant on why singletons are bad, by Steve Yegge. Basically you shouldn't use singletons in almost all cases, you can't really know that it's never going to be needed in more than one place.

提交回复
热议问题