Concept

Decoupling

Definition

Decoupling is the practice of designing components so each one knows as little as possible about the others. A decoupled component depends only on small, stable interfaces, not on the internal details of its collaborators.

The opposite, tight coupling, links components so closely that a change in one forces changes in many. Decoupled code limits the blast radius of any modification, which is what makes a system safe to evolve.

Why it matters

How it works

Several pragmatic habits produce decoupling. Program to interfaces rather than concrete types. Follow the Law of Demeter so an object talks only to its immediate collaborators, not to objects reached by chaining through them. Prefer events and messages over direct calls when components should not depend on each other's lifecycle.

The Pragmatic Programmer authors frame the goal as building a system from independent, replaceable parts. Each part should be like a brick: it has a clear, minimal connection to its neighbors, and you can swap it without dismantling the wall.

Where it goes next

Continue exploring

Tags