What is Dependency Injection and why is it useful?
Dependency Injection (DI) is a design pattern that allows an object to receive its
dependencies from an external source rather than creating them itself. This promotes loose
coupling, enhances testability, and simplifies code maintenance.
Benefits:
- Improves modularity
- Enables easier unit testing (via mock dependencies)
- Promotes adherence to SOLID principles (especially the Dependency Inversion
Principle)