Sitemap
Better Programming

Advice for programmers.

Dependency Inversion vs. Dependency Injection

Straightforward and simple

4 min readFeb 28, 2022

--

Press enter or click to view image in full size
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.

Press enter or click to view image in full size

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…

--

--

Guy Erez
Guy Erez

Written by Guy Erez

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

Responses (21)