Skip to content
IT glossary
ProgrammingUpdated December 3, 2026

Coupling and cohesion

Связанность и связность

Coupling describes how much one part of a program depends on another. Cohesion describes how well the code within one part works together toward a single purpose.

Also known as: coupling, cohesion, зацепление

Two ways to look at a module

Coupling is about what crosses a boundary. A checkout module is tightly coupled to shipping if it reads shipping's database tables directly: renaming a column can break checkout even when the way shipping fees are calculated hasn't changed. Depending on a stable operation such as quoteShipping instead lets checkout ask for a price without knowing how the shipping module produces it.

Cohesion is about what belongs inside the boundary. A shipping module that checks whether an order qualifies for a rate and then calculates the fee has a clear purpose. If the same module also resets customer passwords, those responsibilities share a home but not a purpose: changing the password policy has nothing to do with a carrier's rates.

The usual goal is loose coupling between modules and high cohesion within them. These are separate properties. A module can have one clear job and still rely on the private details of several other modules.

Example: calculating a checkout total

def checkout_total(subtotal, address, quote_shipping):
    return subtotal + quote_shipping(address)

The caller supplies quote_shipping. Checkout can use a database-backed implementation or one that calls a carrier API without changing how it computes the total. It still depends on a contract: what address data the operation accepts, what currency and units it returns, and how it reports that no quote is available. The improvement isn't that the dependency disappeared; it's that checkout no longer needs to know where the rates come from. The rules for choosing a rate stay together in the shipping module.

What to look for in a code review

  • Trace a likely change. If replacing a storage implementation requires editing several callers even though their needs haven't changed, the boundary probably exposes too much. Look beyond imports: a shared database schema or an undocumented requirement to call methods in a particular order can also create tight coupling.
  • Ask what changes together and why. Keep rules together when they implement the same policy and need to stay consistent. A utils file that mixes pricing, password validation, and date formatting may be convenient to import, but its contents have little in common.

Adding an interface doesn't automatically help. An interface that exposes raw database rows still ties callers to the schema. Nor does splitting a module into smaller pieces guarantee better design: if a single pricing rule must now be updated in three places, the new boundaries may make the code harder to maintain.

How it comes up in interviews

In a refactoring or system design interview, describe a concrete change and trace its impact before and after your proposal. For example, replacing the carrier API should affect the shipping implementation, not checkout, as long as the quote contract stays the same. If the contract must change to include delivery speed, say which callers would need updating. That distinction shows what your design isolates and what still has to change together.