VOOZH about

URL: https://www.geeksforgeeks.org/system-design/dependecy-inversion-principle-solid/

⇱ Dependency Inversion Principle - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Dependency Inversion Principle

Last Updated : 21 Jan, 2026

The Dependency Inversion Principle (DIP) is a key SOLID principle that reduces tight coupling between classes. It encourages high-level modules to depend on abstractions rather than concrete implementations, making systems more flexible and maintainable.

The Dependency Inversion Principle states that high-level modules should not depend on low-level modules; both should depend on abstractions, and abstractions should not depend on details.

Points of Dependency Inversion Principle

  • High-level classes should depend on abstractions, not on concrete implementations.
  • Low-level classes should also follow abstractions, reducing tight coupling.
  • This principle improves flexibility and maintainability of the code.
  • It allows changes in implementation without affecting higher-level logic.

Output
developer added
designer added

This can be easily be visualized by the following UML Diagram.

👁 11
  • The lower-level details are directly exposed to the higher-level class, so there is no abstraction.
  • The Manager class must know the exact types of workers it supervises, increasing dependency.
  • Adding a new worker type (e.g., QA) requires modifying the Manager class.
  • This tight coupling highlights the need for the Dependency Inversion Principle to improve flexibility and design.

Output
developer added
designer added

Now if any other kind of the employee is added it can be simply be added to Manager without making the manager explicitly aware of it. Now to add another class of employee we can simply call

class QA(Employee):
def Work():
print "testing everything out there"
a.add(QA())

The creation of the abstraction between different employees and Manager has resulted in very good looking design code which is easily maintainable and extendable.Please have a look into the UML diagram below.

👁 22

In this code, the manager doesn't have an idea beforehand about all the type of workers that may come under him/her making the code truly decoupled. There are many design patterns where this is a core idea and other things are built upon it.

Comment

Explore