What is cohesion vs coupling and how do SOLID principles address both?
Answer
Cohesion measures how related a module's internal elements are to each other; coupling measures how dependent one module is on another. The ideal is high cohesion, low coupling. SOLID addresses cohesion through SRP — a class with one responsibility has high cohesion by definition — and ISP — interfaces that reflect a single role are highly cohesive. SOLID addresses coupling through DIP — depending on abstractions instead of concretions reduces coupling between modules — and OCP — extending via new classes rather than modifying existing ones avoids increasing coupling. LSP enables polymorphism safely, allowing high-level modules to remain decoupled from specific implementations while trusting the behavioral contract.
Previous
How do SOLID principles apply to microservices?
Next
How do you apply SOLID in a legacy codebase?
More SOLID Principles Questions
View all →- Intermediate How would you refactor a class that violates SRP?
- Intermediate How does the Strategy pattern support OCP?
- Intermediate What are the conditions for LSP compliance?
- Intermediate How does ISP prevent "fat interfaces"?
- Intermediate What is the difference between DIP and dependency injection containers?