Concept

Temporal Coupling

Definition

Temporal coupling is a dependency on time or ordering. Two pieces of code are temporally coupled when one must run before the other, or within a particular window, for the program to behave correctly, even though that ordering requirement is not expressed in the interface.

Because the constraint is implicit, temporal coupling is easy to violate by accident. A method named initialize that must be called before process, or a configuration step that must happen before a connection opens, both encode order requirements that the type system and method signatures do not advertise.

Why it matters

How it works

The remedy is to make ordering either explicit or unnecessary. When a step genuinely must precede another, encode that in the design: have the second operation accept the result of the first as an argument, or use a builder that cannot produce an object until required steps are complete. The compiler then enforces what was previously a tribal convention.

When order is not truly required, remove the coupling entirely. Analyzing a workflow as a dependency graph rather than a fixed sequence often reveals that many steps are independent and can run concurrently. Pragmatic designers ask, for every imposed sequence, whether the order is essential or merely habitual.

Where it goes next

Continue exploring

Tags