⊗
Self-service
⇅
Injected
Car builds its own Engine and Wheels
«composition root»
Assembler / main()
builds the parts, wires them in
builds ↓
PetrolEngine
hard-wired inside Car
Wheels
hard-wired inside Car
Car
drives — but also makes its own parts
new PetrolEngine(); new Wheels();
Tray · disabled — the Car builds its own engine
Who controls construction?
The Car (inside itself)
Swap a part without touching
Car
?
✗
No
Unit-test
Car
with a fake part?
✗
No
—
—
▸
Hollywood Principle:
“Don't call us, we'll call you.” Flip to
Injected
and hand parts in from the
assembler
— the
Car class never changes
.