Coupling vs Cohesion
Coupling and cohesion are both ways to judge how well code is split, but they look at different things. Coupling is how much one part leans on other parts. Cohesion is how well the code inside one part fits together. Good design aims for low coupling and high cohesion. Each part does one thing and needs little from the rest.
Coupling
How much one part of a program leans on another.
Coupling is how much one part of a program depends on another. Tight coupling means a change in one part forces changes in the other. Loose coupling means parts only know a little about each other, often through a small interface. Loosely coupled parts can be changed, tested and replaced on their own. Good design aims for loose coupling between parts.
Cohesion
How well the code in one part fits together.
Cohesion is how well the code in one part of a program fits together. High cohesion means every function in a module serves the same purpose. Low cohesion means a module is a grab bag of unrelated jobs. High cohesion makes code easy to find and easy to name. It goes with loose coupling. Parts that do one thing need each other less.
In one line
- Coupling
- How much one part of a program leans on another.
- Cohesion
- How well the code in one part fits together.