Problems with Singleton Pattern

后端 未结 7 589
渐次进展
渐次进展 2020-11-27 12:16

I\'ve been reading about Singleton pattern for last few days. The general perception is that the scenarios where it is required are quite few (if not rare) probably because

7条回答
  •  一个人的身影
    2020-11-27 12:50

    I wouldn't necessarily equate Singletons with Globals. Nothing should stop a developer from passing an instance of the object, singleton or otherwise, as a parameter, rather than conjure it out of the air. The intent of hiding its global accessibility could even be done by hiding its getInstance function to a few select friends.

    As far as the unit testing flaw, Unit means small, so re-invoking the app to test the singleton a different way seems reasonable, unless I'm missing something the point.

提交回复
热议问题