📎 Webclip
Dependency Inversion vs. Dependency Injection
The article separates dependency inversion from dependency injection. Dependency inversion is presented as a design principle that asks code to depend on high-level abstractions rather than low-level implementations. Dependency injection is presented as a pattern that creates a dependency outside the code that uses it and supplies it at runtime, which makes code more configurable and easier to test.
It also explains why the word inversion is used. In older layered architectures, higher-level components depended directly on lower-level components. The inverted approach reverses that direction by relying on abstractions instead of concrete details.
Reading notes#
- Dependency inversion is a design principle that favors high-level abstractions over low-level implementations.
- That approach keeps code agnostic to implementation details and easier to adapt when implementations change.
- Dependency injection is a design pattern that separates creation from use and provides objects at runtime.
- Injecting dependencies can make code more configurable and easier to test by allowing mocks.
- The article connects dependency injection to dependency inversion by saying injection helps code rely on abstractions.
- The term inversion refers to older layered architecture, where higher-level components depended directly on lower-level components.
- The inverted model shifts that dependence toward abstractions instead of concrete components.
