liveBook · Manning

Cohesion

As explained in Functional Design and Architecture: Examples in Haskell

Cohesion is the degree to which the responsibilities and internals of a software component belong together.

Cohesion measures whether a component’s responsibilities and internals belong together. High cohesion keeps a component focused; low cohesion blurs its responsibility and makes complexity harder to manage. section 1.3 section 1.3.1

A component becomes cohesive when it concentrates on one responsibility instead of reading devices, correcting data, and communicating with remote systems at once. Interfaces help separate those concerns and distribute responsibility more clearly. section 1.3.1

Temperature observation

A low-cohesion Observer reads a native thermometer, converts Kelvin values, applies a hard-coded correction, and sends the result to a server. A better design gives the Observer an ISensor and an IConnection: it reads sensor data and sends it, while concrete implementations handle device details and external connections. The same principle applies to functional code; Haskell functions can also combine unrelated effects and become highly coupled.

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines blurred responsibility, diagnoses a coupled implementation, and refactors it through interfaces without detailing cohesion metrics.
Examples
Uses a thermometer-to-server Observer, ISensor and IConnection interfaces, and an analogous Haskell temperature workflow.
What you can do after
Evaluate and refactor components by isolating responsibilities behind interfaces and checking cohesion across object-oriented and functional code.
How it connects
Connects cohesion with coupling, the single responsibility principle, interfaces, modularity, inversion of control, and functional programming.

Also explained in

Compare how 4 books explain cohesion →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.