What is the difference between Strategy pattern and Dependency Injection?

后端 未结 9 1736
长情又很酷
长情又很酷 2020-12-04 06:13

Strategy pattern and Dependency Injection both allow us to set / inject objects at run time. What is the difference between Strategy pattern and Dependency Injection?

9条回答
  •  渐次进展
    2020-12-04 06:40

    Actually, dependency injection also looks very similar to the Bridge pattern. To me (and according to the definition), the Bridge pattern is to accommodate different versions of the implementation, while the Strategy pattern is for the totally different logic. But the sample code looks like it's using DI. So maybe DI is just a technic or implementation?

提交回复
热议问题