© Matthias Noback 2018
Matthias NobackPrinciples of Package Designhttps://doi.org/10.1007/978-1-4842-4119-6_5

5. The Dependency Inversion Principle

Matthias Noback1 
(1)
Zeist, The Netherlands
 
The last of the SOLID principles of class design focuses on class dependencies. It tells you what kinds of things a class should depend on1:

Depend on abstractions, not on concretions.

The name of this principle contains the word “inversion,” from which we may infer that without following this principle we would usually depend on concretions, not on abstractions. The principle tells us to invert that direction: we should always depend on abstractions.

Example of Dependency Inversion: the FizzBuzz Generator

There is a well-known programming assignment that serves ...

Get Principles of Package Design: Creating Reusable Software Components now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.