1

In both the Strategy Pattern and in Inversion of Control you can exchange parts of an object that allows scalability and easy-to-exchange parts. I am referring to this and this

Both use an interface and call the function of the interface. Am I missing something?

1
  • 2
    An Interface is really its own "pattern." Strategy and IoC both use the "interface pattern." But that doesn't make them the same pattern. Commented Dec 23, 2019 at 21:59

1 Answer 1

6
  • Inversion of Control is a means of constructing objects at initialization time. You design each component of your application to use dependencies, but have something outside the component supply all the requirements.
  • Strategy Pattern is a means of abstracting away different algorithms, but still consume them in a consistent manner. There is nothing in a strategy pattern that concerns itself with object construction or selecting the algorithm.

In a manner of speaking, you could argue that Inversion of Control is a specialized application of the Strategy Pattern for object construction. The Strategy Pattern is a bit more inclusive than that, but the benefit is that you can write your control logic once and have very different behavior based on the implementation of the selected algorithm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.