Dependency Inversion
Start course

In this course, we explore the SOLID principles one by one and look at how they work.

Learning Objectives

  • Understand what SOLID principles are

Intended Audience

  • Beginner Java developers
  • Anyone with a desire to learn about SOLID principles


  • Basic Java knowledge

Hello, dear friends. In this video, we will examine Dependency Inversion Principle. So, let's begin. The dependency inversion principle is the last part of solid principles. Now, this principle consists of two rules. High level modules should not depend on low level modules. Both should depend on abstractions. Abstractions should not depend on details, details should depend on abstractions. This principle is primarily concerned with reducing dependencies among the code modules. We can think of it as needing the low level objects to define contracts that the high level objects can use. Without the high level objects, needing to care about the specific implementation the low level objects provide. Actually, this principle shows us the importance of interfaces and abstract classes. So, let's go on with an example. First, we will create a structure to hold our log files. Hold file log, and log context.

Now, let's create a new class for DB logs. Hold DB logs and log context. Now, let's use them in a new class. Manage logs first define instance. Now, call methods. Now, this structure will work without any problems, but in this structure, manage logs classes dependent on the other two classes. And one day, you may want to change one of these classes and it will be very difficult. You have to write a new class but this time your class will be dependent on the new class. So, this method will not solve our dependency. For this, we have to create our structure with interfaces. First, we need an interface. Now, let's change our class structure derived from interface. Done. Now, in managed class, we don't need to define these classes. We only add interface and call methods. Now, we adjust our project with interfaces and that's all. That's all for now. In the next video, we'll begin discussing patterns. So, I'll see you in the following video.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.