Coupling and Cohesion

Categories
Architecture
Sources
Fundamentals of Software Architecture

Two foundational measures of module structure. Coupling is the degree of interdependence between modules; cohesion is the degree to which the elements inside a module belong together. Good structure minimizes coupling between modules and maximizes cohesion within them.

Why it Matters

Together they predict how a system can change. High cohesion means a module has one clear reason to change; low coupling means that change does not ripple outward. Most modularity advice, deep modules, information hiding, single responsibility, is a way of raising cohesion and lowering coupling.

Signals

  • A module that does several unrelated things (low cohesion).
  • A change in one module forcing edits in many others (high coupling).
  • "Shotgun surgery," where one logical change is scattered across many modules.

Benefits

Localized change, independent testing and reuse, and a clear home for each responsibility.

Risks

Chasing zero coupling produces excessive indirection; splitting for its own sake lowers cohesion; collapsing things together for convenience raises coupling.

Tensions

Reducing coupling can mean duplicating a little rather than sharing (which would add a dependency), and maximizing cohesion can pull toward many small modules that then must coordinate. The judgment is which dependencies are worth their cost.

Examples

A module that owns one decision and exposes a narrow interface is cohesive and loosely coupled; a "utils" grab-bag that half the system imports is low-cohesion and high-coupling.