I am reading about SOLID principles and have just read that Dependency Inversion (DI, to be distinguished here from Dependency injection, which is one way of achieving the inversion) is an extension to the Open-Closed Principle (OCP). How is that exactly meant, if OCP is about making class extensible without touching the original code, basically.
The DIP requires your classes to depend on abstractions. Because you can always provide different implementations of these abstract dependencies, they create natural extension points that allow you to modify the behavior of the class without changing the class itself.
This, of course, is exactly what the OCP requires.
For example, imagine you have a
TaxReporter that requires an instance of an interface
ITaxCalculator during construction. By providing a different implementation of
ITaxCalculator, you have modified the way reports are generated without touching the
Inheritance is not the only way to realize the OCP.