The dependency inversion principle is about decoupling software modules. That is, making them as separate from one another as possible.
The principle states that high-level modules should not depend on low-level modules.
Instead, they should both depend on abstractions.
Additionally, abstractions should not depend on details, but details should depend on abstractions.
In simpler terms, this means instead of writing code that relies on specific details of how lower-level code works, you should write code that depends on more general abstractions that can be implemented in different ways.
This makes it easier to change the lower-level code without having to change the higher-level code.
Here’s a code that violates the dependency inversion principle: