What is the difference between coupling and cohesion?
Quick Answer
Coupling is how much one module depends on the internals of another — you want it loose. Cohesion is how focused a module is on a single well-defined purpose — you want it high. The goal is high cohesion within a module and loose coupling between modules.
Coupling is about the connections between modules — how much module A has to know about how module B works internally. Tight coupling means a change in B forces a change in A, so you want it loose, achieved by depending on interfaces and keeping the contact surface small. Cohesion is about the inside of a module — whether everything in it is working toward one purpose. A class that parses files, talks to the database and sends emails has low cohesion. The target is each unit doing one thing well, with thin, stable connections between units, so changes stay contained.
- Loose coupling: depend on abstractions, pass data not behaviour, minimise the surface area between modules — makes change and testing local.
- High cohesion: everything in the class relates to its one job; a class that does validation and emailing and persistence has low cohesion (violates SRP).
- Symptoms of trouble: a change ripples across many files (too much coupling); a “utils” or “manager” god class (low cohesion).