Skip to content

Coupling vs Cohesion

Coupling and Cohesion are two fundamental concepts for measuring the quality of software design. They are inversely related — good design has high cohesion and low coupling.

  • Cohesion — How focused is a single module/class? (internal)
  • Coupling — How dependent are modules/classes on each other? (external)

Cohesion refers to how closely related the responsibilities of a single module/class are.

  • Class has a single, well-defined purpose
  • All methods relate to that purpose
  • Easy to understand and maintain
  • Class does unrelated things
  • Methods are not related to each other
  • Hard to understand, name, and maintain

Coupling refers to how dependent one module/class is on another.

  • Classes interact through well-defined interfaces
  • Changes in one class rarely affect others
  • Classes know too much about each other
  • Changes in one class ripple through the system

GoalDescription
Aim for High CohesionEach class should have one clear responsibility
Aim for Low CouplingClasses should communicate through minimal interfaces
Use DIReduces coupling significantly
Program to InterfacesReduces implementation coupling
Single ResponsibilityNaturally leads to high cohesion

ConceptGood DesignBad Design
Cohesion (internal)High (focused purpose)Low (does everything)
Coupling (external)Low (loosely connected)High (tightly connected)
GoalHigh Cohesion + Low Coupling

Previous Topic: Dependency → Next Topic: Advanced Concepts →