![]() |
VOOZH | about |
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.
developer added designer added
This can be easily be visualized by the following UML Diagram.
👁 11developer 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.
👁 22In 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.