Cohesion & Coupling

The five kinds of coupling that actually differ in cost, why cohesion is the other half of the same question, and how fan-in, fan-out and cycles show up in a real dependency graph.

Cohesion

A module is cohesive when its parts change for the same reason. Cohesion and coupling are one question asked twice: what belongs together, and what may know about what.

Q · What belongs in this module, given that anything I take out of it becomes a dependency between two modules?
Kinds of Coupling

Data, control, temporal, shared-state and implementation coupling are not degrees of one thing. They differ by an order of magnitude in cost, which is why the taxonomy is worth having.

Q · Two modules are connected. Which kind of connection is it, and what will it cost me when a requirement changes?
Temporal Coupling

When calls must happen in an order the type system does not know about, the ordering lives in someone's head — and heads leave.

Q · How do I design an interface so that the invalid call order cannot be written, rather than merely documented?
Shared-State Coupling

Two modules connected through a mutable structure neither of them owns. The most expensive kind, because there is no list of who writes to it.

Q · Two modules never call each other and still break each other. What connects them, and how do I make that connection visible?
Fan-in and Fan-out

How many modules depend on this one, and how many does it depend on. Both are signals about where change lands — and neither, on its own, is a verdict.

Q · A module has a lot of dependents, or a lot of dependencies. Which of those is a problem, and how would I tell?
Dependency Cycles

A cycle turns three modules into one. You cannot reason about, test, initialize, extract or delete any of them without the others.

Q · Three modules each call the next and the last calls the first. What has that actually cost me?
Afferent and Efferent Coupling

Who depends on me, and what do I depend on. A useful pair of questions, a widely published pair of metrics, and a gap between the two that is worth being honest about.

Q · Given who depends on this module and what it depends on, what can I actually conclude — and what am I about to over-conclude?