liveBook · Manning

Cohesion

As explained in Shipping Go: Develop, deliver, discuss, design, and go again

Cohesion is the degree to which the responsibilities of a software module or component belong together.

Cohesion describes how well a component’s responsibilities belong together. Focused components have a clear purpose; broad components group responsibilities arbitrarily and are harder to reason about. section 6.3

Validation responsibilities

A general Validation class may collect many kinds of validation. UserRegistrationValidation has a narrower purpose: validating one step in a business process. section 6.3

Table 6.1 Cohesion is used to define how well a structure or class is defined. (view table figure)

High cohesion

Clearly defined purpose and method definitions

Low cohesion

Broad responsibilities that are often all in one class or struct

Compare clearly defined purposes and methods with broad responsibilities concentrated in one structure. section 6.3

How Shipping Go: Develop, deliver, discuss, design, and go again covers it

How deep it goes
Defines high and low cohesion and illustrates each with class examples, without offering a measurement method.
Examples
Contrasts Validation with UserRegistrationValidation and broad responsibilities with clearly defined structures.
What you can do after
Evaluate whether a component groups one well-defined task or combines broad responsibilities.
How it connects
Connects cohesion to interfaces, dependency injection, decoupled tests, 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 Shipping Go: Develop, deliver, discuss, design, and go again. The section links point to the parts of the book it draws on.