juniorDependency Injection
What is the difference between Tightly Coupled and Loosely Coupled code?
Updated Apr 28, 2026
Short answer
Tightly coupled code relies heavily on specific concrete classes, while loosely coupled code relies on abstractions (interfaces).
Deep explanation
When code is tightly coupled, a change in one class forces changes in all classes that depend on it. Loosely coupled code isolates changes. DI is the primary mechanism for achieving loose coupling by pushing the responsibility of object creation outward.
Real-world example
A TV remote that is permanently wired into a specific TV brand (Tight) vs a universal remote that works via infrared standards (Loose).
Common mistakes
- Implementing an interface but still manually using `new` to instantiate the implementation inside the consumer.
Follow-up questions
- How do interfaces promote loose coupling?