The Dependency Inversion Principle

Clean Code, Episode 13

By Uncle Bob

58 minAug 2012

And now, at last, it's time for the Dependency Inversion Principle -- the final principle in the SOLID suite.

Go back in time with Uncle Bob to 1979, when he was just a noobie software developer with only 6 years experience. Walk with him through the tale of telephone test equipment using 8085 microprocessors with 32K of RAM and 32K of ROM. See how he first discovered the magic and power of inverting source code dependencies in order to turn those ROM chips into independently deployable components.

Then hop into the time machine to the early '90s when Uncle Bob was becoming an accomplished C++ programmer. See how he, and his team, struggle, and at first fail, to create a huge reusable framework. Watch as he discovers the key to reuse, and to building frameworks that many applications can reuse.

In this episode we'll learn what dependencies are. We'll study the difference between source code dependencies, and runtime dependencies. We'll learn why that difference is important, and we'll learn how to invert certain key source code dependencies so that they oppose their corresponding runtime dependencies.

Then we'll spend some time looking at two case studies. First we'll look at IO drivers, and how they use dependency inversion to create device independence. Then we'll look at the good old furnace example, and see how dependency inversion allows us to separate high level policy from low level detail in order to create a plug-in architecture.

So get ready for a wild ride through time and technology and we DIP in to the Dependency Inversion Principle.