What is the difference between Strategy pattern and Dependency Injection? -
Both strategy patterns and dependency injection allow us to set / injection objects while running. What is the difference between strategy pattern and dependency injection?
Di and strategy work in the same way, but the strategy is used for more subtle and short-term dependencies. is.
When an object is configured with a "fixed" strategy, for example when the object is formed, the difference between strategy and de-blur But in the DI scenario it is more unusual that the dependence of objects varies in their lifetime, while it is not uncommon with the strategy.
In addition, you can pass the arguments of methods in a manner, while the related concept method is that logic injection is not comprehensive and is used only in the context of most automated tests.
The strategy is focused on the intention and encourages you to create an interface with different implementations that follow the same behavioral agreement. DI is more about implementing and implementing some behaviors.
With DI, you can dissolve your program for other programs to be able to swap some parts of the implementation. The interface used in DI with a single implementation is very common. With a single concrete implementation (sometimes) a "strategy" is not a real problem, but perhaps close to D.
Comments
Post a Comment