Cohesion is how well the responsibilities inside a software component belong together. Think of a well-written paragraph: every sentence contributes to one clear idea. A class devoted to calculating shipping costs is similarly focused. A class that mixes authentication, logging, and currency formatting is more like a paragraph that jumps from cooking to car repair to the weather. section 3.3
Cohesion looks inside a module; coupling looks at dependencies between modules. Together, they help assess separation of concerns. The goal is focused components that connect without depending on each other's internal details. This thinking applies from methods and classes up to components and entire systems. section 3.3 section 3.7
Keep related behavior with its data
An Order object that only holds data while its calculation and validation behavior is scattered elsewhere lacks cohesion. It also cannot protect its own state: another class could set its total to a negative value. Keeping related behavior with the data helps make the object's responsibility clear. section 4.7.2
More focused classes can make changes easier to locate and pieces easier to test independently. The tradeoff may be more files to manage: separating payment, validation, and notification work adds structure, but avoids leaving those jobs tangled together. section 3.5.4
Try a quick cohesion audit:
- Pick a method or class over 50 lines long, or one that feels complicated and intimidating. section 3.9
- Add a comment describing what each block does, then read only the comments. Do they tell one focused story or describe several unrelated jobs? section 3.9
- Optionally ask an AI assistant to identify responsibilities as a second set of eyes. Use your own judgment to assess its suggestions. section 3.9






