Card 05/ 05

RecapDifficulty: Beginner1 min

Recap: Why Spring Exists

The cost of a hard-coded new, the principle and the technique, and the shape they share.

Why Spring exists comes down to the four ideas below, each listed with the card that covers it.

What the topic established, and which card it was on
The ideaWhere
A hard-coded new ties a class to one implementation, and every test and swap pays for itHard-Coded Dependencies and Inversion of Control
Inversion of Control is the principle; Dependency Injection is the technique that carries it outHard-Coded Dependencies and Inversion of Control
A constructor parameter is the whole technique, and needs no frameworkDependency Injection Example: A Repository Passed to the Constructor
The same shape works for any dependency: depend on an interface, let the caller chooseDependency Injection Example: A Mail Client Instead of a Database

Spring's container is what does this handing-in automatically, for every bean in an application, and it is what the rest of Spring Core is about.