Cohesion: Why Should Work That Belongs Together Stay Together?

Cohesion: Why Should Work That Belongs Together Stay Together?

Cohesion describes whether the contents of one part are organised around the same concern. High cohesion does not mean having little content. It means that each responsibility has a clear reason to belong with the others. Low cohesion often results when unrelated work is placed together merely by convenience.

Suppose an invoicing module in a bookkeeping app calculates totals, draws buttons and sends marketing emails. A change to promotional copy may then disturb the invoicing logic. If the module is narrowed to invoice creation and status management, while interface and marketing work sit elsewhere, the boundaries of change become clearer.

Cohesion differs from coupling. Cohesion asks whether the inside of a part serves one responsibility; coupling asks how deeply separate parts depend on one another. A sound structure usually seeks high cohesion and low coupling, but related functions need not all occupy one place. The better test is whether they tend to change for the same reason. Cohesion matters because it lets a part explain its responsibility in one stable sentence.


Discover more from Geoffrey Chen

Subscribe to get the latest posts sent to your email.