Comparison
CohesionvsSingle responsibility
Cohesion
the code for one job is spread over four files, and each of those files also does three unrelated jobs.
How much the things inside one module belong together. High cohesion means a module has one reason to exist and everything in it serves that reason; low cohesion means the module is a drawer. It matters because cohesion is what makes a boundary findable: when the code that changes together lives together, a feature is one file to open rather than a search across the repository.
Full entry →Single responsibility
two teams keep editing the same class for two entirely unrelated reasons and keep colliding.
The rule that a module should have one reason to change — which is a statement about people, not about code size. The useful reading is the original one: a responsibility is a stakeholder whose request causes an edit, so a class serving the finance team and the support team has two. It comes up whenever a shared file becomes a merge-conflict hotspot, which is the symptom the principle was invented to describe.
Full entry →