When to use Dependency Injection

前端 未结 8 960
野性不改
野性不改 2020-12-01 00:19

I\'ve had a certain feeling these last couple of days that dependency-injection should really be called \"I can\'t make up my mind\"-pattern. I know this might sound silly,

8条回答
  •  北海茫月
    2020-12-01 00:30

    Aside from loose coupling, testing of any type is achieved with much greater ease thanks to DI. You can put replace an existing dependency of a class under test with a mock, a dummy or even another version. If a class is created with its dependencies directly instantiated it can often be difficult or even impossible to "stub" them out if required.

提交回复
热议问题