The SOLID Principles — Dependency Inversion Principle (DIP)

KRISHNA KISHORE V
4 min readJun 17, 2023

In the previous two articles (this & this), we discussed the first four SOLID principles: SRP, OCP, LSP, and ISP. In this article, we will continue with the 5th principle which is Dependency Inversion Principle or DIP in short.

Dependency Inversion Principle

The Dependency Inversion principle says two things.

  1. The high-level modules should not depend on the low-level modules. Instead, both should depend on the Abstractions.
  2. The Abstractions should NOT depend on the Details. The Details should depend on the Abstractions.

The DIP is discussed around the HAS-A relationship. First, just look at the four new terms introduced here: High-Level, Low-Level, Abstractions, and Details. Let’s understand these terms from the Object-oriented perspective.

  1. High-Level object: Any object referencing another object (HAS-A relationship).
  2. Low-Level object: The object that is being referenced. (HAS-A relationship in the reverse direction)
  3. Abstractions: Abstract class or an Interface.
  4. Details: Concrete implementations of the Abstractions.

So, now let's understand the two things that the DIP says.

1. High-level modules should NOT depend on the low-level modules. Instead, they should depend on

--

--

KRISHNA KISHORE V

Full Stack Tech Lead | Software Consultant | Technical Content Writer