Bookmarks

Coupling

A measure of how closely the modules of a system depend on each other: the less one module knows about the internals of another, the looser the coupling.

Also: inter-module coupling, module dependency

checked 8 Nov

All terms

Coupling answers the question “how tightly are the modules connected”: does the payment module know about the internal tables of the orders module, or does it talk to it only through an interface? The looser the coupling, the more independently each module can be changed and tested. Loose coupling is almost always the goal; tight coupling is a source of fragility.

Types of coupling

In the classification of structured design, kinds of coupling are distinguished by what exactly connects the modules, from the least desirable to the most useful:

KindHow the modules are connected
content couplingone module reaches into the internal data or code of another
common-environment couplingmodules read and write the same global variables or files
control couplingone module passes flags to another that determine its behaviour
stamp couplingmodules exchange a whole structure although only individual fields are needed
data couplingmodules exchange only small amounts of data through parameters

Why loose coupling is good

  • a change inside one module does not drag edits through its neighbours — one module is changed, not a whole chain;
  • a module can be tested on its own by substituting test doubles for its neighbours;
  • teams work in parallel: the contract between modules remains stable, while each team changes the internals on its own;
  • a module is easier to extract into a separate service when the need arises.

Tight coupling shows itself as a chain reaction of edits: to add a single field to an order, you have to change the orders module, the payment module, the delivery module and the shared database schema. Fowler and Lewis state this as a principle of microservices: services should be as loosely coupled and as highly cohesive as possible.

How coupling is reduced

  • communicate through narrow interfaces and contracts rather than shared tables and global variables;
  • pass data, not control flags;
  • accept narrow structures instead of handing a neighbour the whole object;
  • share data between modules through events or copies of the data rather than direct access to the database.

Origin of the term

The term was established by the 1974 article “Structured Design” by Wayne Stevens, Glenford Myers and Larry Constantine on structured design; the same article introduced the paired notion of cohesion. Since then the pair “coupling and cohesion” has been the standard language for discussing modularity.

Sources

the term is written from these pages

Verified 8 Nov

Not to be confused with

what it is mixed up with and how it differs

  • module cohesion

    Cohesion is about how unified the contents of a single module are from the inside; coupling is about the strength of the dependency between different modules. Cohesion is increased, coupling is reduced.

  • distributed monolith

    A distributed monolith looks like services but keeps tight coupling: it is impossible to change one service without synchronously changing all the others.

In depth in the references

where the topic is covered in detail