Intro

The fifth and last principle of SOILID Principles of OOP. Like most of the principles, this one also promotes abstraction. By making the code’s dependencies refer to abstractions, it makes the system more flexible.

Instead of relying on concrete implementations, only refer to abstractions, i.e. interfaces and classes.

Explanation

We strive to make the source code’s dependencies point opposite of the control flow. Meaning high-level modules Don’t rely on low-level modules, this increases modularity and makes modifications (fixes not updates, remember Open Closed) easier.

How?

  1. Avoid referring to concrete implementations of abstract classes or interfaces.
  2. Don’t derive from concrete implementations.
  3. Don’t override concrete implementations’ methods and functions.

However this is easier said than done, it’s near impossible to achieve DIP 100%. So when you do instantiate concrete classes, gather them and isolate them in the main method.


References