DSA Factory
Free SOLID and design smells lessonsSOLID and design smells · Stage 1 · Substitution and dependencies · Step 3

Dependency inversion and injection

Why high-level code should depend on abstractions, and how passing dependencies in makes code testable and flexible. About 14 minutes.

Quick check

What does the dependency inversion principle say a high-level policy class should depend on?

  1. AAn abstraction (interface) that low-level details implement
  2. BThe concrete low-level classes it uses
  3. CNothing at all
Show the answer

An abstraction (interface) that low-level details implement. The details then depend on the abstraction too.

Lock it in

4 questions on this idea

Short questions that apply the idea to new cases: trace it, work out a number, put steps in order. A wrong answer explains itself.

Answer them in your browserFree account, no card. Your progress is saved, and the idea comes back in a quick review later.
Sign up free to solve