Dependency Inversion Principle

Taylan Can Hardal
2 min readFeb 27, 2022

Hey everybody it is fifth and last principle of SOLID Principles. This principle means that a high-level modules should not depend on low-level modules. Both should depend on abstractions. So abstractions should not depend on details. Details should depend on abstractions.

Let’s say you have a customer and he is a car mechanic. He can change the tires but that’s it. He cannot do anything else. It asks you for a program. You wrote a program and gave it to him. After that it came back to you. He’s making a deal with another auto mechanic. The other guy is an electrician. You have to rewrite the program.

Example Project

In order to learn in detail, the correct usage and the wrong usage should be examined together.

Wrong Usage :

We wrote down the duties of both of our mechanics. We do not have any operational problems at the moment. Our project works without errors. But now, if only one new mechanic is added, we will have to intervene in 3–4 different places in the code. In other words, there are structural errors in our project. Let’s see how it should be.

Correct Usage :

Now it will be enough to add it into the incoming interface.

It was the last principle. SOLID principles is over. Thanks for reading.

References :

bolŞans…

--

--

Taylan Can Hardal

Software Engineer @Turkcell. Savin’ the Earth. Somewhere