What is the difference between Strategy design pattern and State design pattern?

Honestly, the two patterns are pretty similar in practice, and the defining difference between them tends to vary depending on who you ask. Some popular choices are: States store a reference to the context object that contains them. Strategies do not. States are allowed to replace themselves (IE: to change the state of the context … Read more

Using a Strategy and Factory Pattern with Dependency Injection

There are a few ways of doing this, but the way I prefer is to inject a list of available strategies into your factory, and then filtering them to return the one(s) you’re interested in. Working with your example, I’d modify IShippingStrategy to add a new property: public interface IShippingStrategy { int CalculateShippingCost(Order order); string … Read more