单身反模式
可能重复:
单身人士有什么不好的?
单身人士设计模式:陷阱
我听到很多这个但是没有找到坚定的理由。
Avoid the singleton anti-pattern and replace it with DI.
但为什么?
有状态的单身人士更难以进行unit testing。
我使用无状态单例,我没有看到问题。
由于单例可以实现接口,因此可以使用dependency injection传递它们(并且应该尽可能地传递它们)
可能重复:
单身人士有什么不好的?
单身人士设计模式:陷阱
我听到很多这个但是没有找到坚定的理由。
Avoid the singleton anti-pattern and replace it with DI.
但为什么?
有状态的单身人士更难以进行unit testing。
我使用无状态单例,我没有看到问题。
由于单例可以实现接口,因此可以使用dependency injection传递它们(并且应该尽可能地传递它们)