What is cohesion in software design?

Answer

Cohesion measures how strongly related and focused the responsibilities within a module or class are. A highly cohesive class has all its methods and properties working toward a single, well-defined purpose — like a ShoppingCart class that only manages cart items, quantities, and totals. A low cohesion class has unrelated methods lumped together — like a Utilities class with date formatting, user validation, and file compression. High cohesion is a direct outcome of following SRP. Cohesion is the counterpart to coupling: good design aims for high cohesion and low coupling simultaneously. Cohesion is measured within a module; coupling measures relationships between modules.