Coupling & Cohesion

Difficulty
Importance

The problem

As a codebase grows, some ways of organizing it make a single change ripple through dozens of unrelated files, while other ways keep related logic together and isolate the rest — the difference between the two is almost entirely a matter of coupling and cohesion, and it determines whether a codebase gets harder or easier to change over time.

Why now

Functions and scope already established hiding internals as the default, good practice at the function level; modules and bundling extended that same idea to files. Coupling and cohesion is the general vocabulary for judging how well that hiding principle is being applied across an entire system, not just one function or file.

Mental model

Cohesion asks 'do the things inside this unit belong together' — high cohesion means a module does one clear job. Coupling asks 'how much does this unit know about, and depend on, other units' internals' — low coupling means changing one module rarely forces changes elsewhere. The goal is always high cohesion, low coupling: related things grouped tightly, unrelated things touching each other as little as possible.

Requires

Unlocks

Used in

Projects

  • Identify a tightly coupled pair of modules in a real codebase (one directly reaching into another's internals) and refactor them to communicate through a narrow, explicit interface instead
  • Take a low-cohesion 'utils' file doing five unrelated things and split it into focused, single-purpose modules

Examples

  • A billing module that directly reads and writes another module's internal database tables is tightly coupled — a schema change in one breaks the other unexpectedly
  • A utils.js file containing date formatting, API calls, and validation logic has low cohesion — three unrelated concerns bundled together for no structural reason

Resources

Mastery checklist