1. Home
  2. Training Library
  3. Programming
  4. Programming Courses
  5. Exploring the SOLID Principles in Java

Dependency Inversion


SOLID Principles
What is SOLID?
15m 18s

The course is part of this learning path

Start course

This course looks at the five SOLID principles starting with a little bit of their history before moving on to cover each principle in more detail.

Learning Objectives

  • Learn about the five SOLID principles:
    • Single Responsibility
    • OpenClosed
    • Liskov Principle
    • Interface Segregation
    • Dependency Inversion

Intended Audience

This course is intended for anyone who already has basic knowledge of Java and now wants to learn about Java EE.


Basic knowledge of Java programming.


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 is comprised 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. Now, let's go on with an example. First, we will create a structure to hold our log files. HoldLogFile and LogContext. Now let's create a new class for DBlogs, HoldDBlogs and LogContext.

Now, let's use them in a new class, ManageLogs. First, define instance. Now call methods. Now this structure will work without any problem, but in this structure ManageLogs class is dependent to the other two classes. And today you may want to change one of these classes. So, it will be very difficult. You have to write new class, but that time, your class will be depended to another 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 manage class, we don't need to define these classes. Only we add interface and call methods. Now we adjust our project with interfaces. That's all for now. In the next video, we'll begin discussing design patterns. 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.

Covered Topics