Skip to content
Veltoryx Technologies
ProLesson 3.5Intermediate9 min readUpdated 31 October 2026

Dependency Inversion Principle

Learn the last SOLID principle: make business code depend on small abstractions instead of databases and other details, and learn how it relates to dependency injection and Spring.

Think about how a laptop works with a mouse. The laptop does not know the brand of your mouse. It only knows one standard, USB. Every mouse maker builds to that standard. So you can swap the mouse for another brand, and the laptop never changes. Now imagine the opposite: a laptop that has the wiring of one specific mouse model built into it. Replace the mouse, and you must replace the laptop.

The fifth SOLID principle asks us to design software like the first picture. It has two parts:

  1. High-level modules should not depend on low-level modules. Both should depend on abstractions.
  2. Abstractions should not depend on details. Details should depend on abstractions.

That sounds heavy, so let us translate it step by step.

01The words in plain English

  • High-level code is the part that holds your business rules: what the application is actually for. "When an order is placed, save it and email the customer" is high-level.
  • Low-level code is the part that holds technical details: how to talk to MySQL, how to send mail over SMTP, how to write a file.
  • An abstraction is a small promise, usually an interface, that says what is needed without saying how.

The principle says that business rules should not know about MySQL or SMTP. They should know only small promises such as "something that can save an order", and the technical classes should keep those promises.

Loading the rest of the lesson…