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.