Skip to content
BENIBIX Learn

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.

Development🏗️ Architecture

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.

Example
Jack's checkout code reads the payment firm's data straight from its API. When the firm changes its API, he must fix checkout too. That is tight coupling.
Why it matters
Loose coupling is what lets one team change their part without breaking everyone else's.
Full entry
Development🏗️ Architecture

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.

Example
Lucy's utils file holds date code, email code and price maths. She splits it into three files. Each one now has a clear name and purpose.
Why it matters
When code that belongs together sits together, a change happens in one place. You do not hunt for it.
Full entry

In one line

Coupling
How much one part of a program leans on another.
Cohesion
How well the code in one part fits together.