Coupling

noun

say it: “KUP-ling” /ˈkʌplɪŋ/

How much one piece of code depends on another; the less it depends, the easier both are to change.

What is Coupling?

Coupling is how much one piece of code depends on the details of another. Loose coupling is the goal: you can change one class without breaking the others.

// Tightly coupled: OrderService can only ever use SmtpEmailer
private readonly SmtpEmailer emailer = new();

// Loosely coupled: any IEmailer will do
private readonly IEmailer emailer;

In a sentence

  • “The order desk named every screen, so its coupling to them meant each new screen changed the desk.”

Level: Journeyman · More OOP terms at this level

Updated