Better Programming

Advice for programmers.

Follow publication

Member-only story

Dependency Inversion vs. Dependency Injection

Straightforward and simple

Guy Erez
Better Programming
Published in
4 min readFeb 28, 2022
Photo by Pete Nowicki on Unsplash

I’ve been a software engineer for a few years now, yet every now and then I like to return to the fundamentals. We all “know” that we should follow the SOLID principles by good ol’ Uncle Bob, but common knowledge is not always common practice.

Recently, it dawned on me that I don’t really know the difference between dependency inversion and dependency injection. I know what they mean, roughly, but I wasn’t sure what’s the difference between the two, and moreover, why is it called dependency inversion, what exactly is inverted?
It turns out, like all good things, there’s a story behind it.
But first things first, let’s discuss the difference between the two concepts.

Dependency Inversion

Dependency inversion is a design principle. In simple terms, it means we should not depend on low-level implementations, but rather rely on high-level abstractions. And that makes sense, as it allows us to be agnostic towards the implementation details. Whether we want to change a specific implementation or support other…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Guy Erez
Guy Erez

Written by Guy Erez

Software Engineering Team Lead & On a Quest to Help People Live Purpose-Driven Fulfilling Lives

Responses (22)

Write a response