Show in graph

Software → Software Design

Cohesion

The degree to which the responsibilities inside a module belong together.

Motivation

Cohesion solves the problem of modules that group unrelated responsibilities together.

Where it fits

Cohesion belongs to software design. High cohesion usually makes code easier to understand, test, and change.

Mental model

A cohesive module has a clear reason to exist. Its parts work together toward one focused purpose.

Common mistakes

  • Calling a large utility module cohesive because it is reused everywhere.
  • Grouping code by technical type only, instead of by responsibility.
  • Confusing cohesion with small file size.