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.
What does the dependency inversion principle say a high-level policy class should depend on?
- AAn abstraction (interface) that low-level details implement
- BThe concrete low-level classes it uses
- CNothing at all
Show the answer
An abstraction (interface) that low-level details implement. The details then depend on the abstraction too.
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