Definition:
It states that high-level classes should not depend on low-level classes. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.
low level classes: are those which implement basic and primary operations.
high level classes: are those which encapsulate complex logic and rely on the low level classes.
The Dependency Inversion principle (DIP) helps to loosely couple your code by ensuring that your high-level modules depend on abstractions rather than concrete implementations of lower-level modules.
The Dependency Injection pattern is an application/ implementation of this principle.
Example:
suppose that we have a banking system software. As a part of that software it is necessary to transfer money between accounts. So there is a bank account class which contains 2 properties account number and the balance. also 2 methods addFunds and removeFunds. Continue reading