Cohesion is about how closely related the responsibilities of a module, class, or function are. A cohesive unit does one job and does it well. High cohesion means that everything inside that unit contributes directly to a single, well-defined purpose. Low cohesion means the unit is doing too many unrelated things, which often makes it harder to understand, test, and maintain.
For example, a class that only handles user authentication is cohesive, whereas a class that mixes authentication, report generation, and email notifications is not. High cohesion helps improve clarity, reduces duplication, and ensures that changes are easier to manage.
When systems have high cohesion and low coupling together, they become much easier to test because each part has a clear focus and fewer dependencies on other parts.
For example, a class that only handles user authentication is cohesive, whereas a class that mixes authentication, report generation, and email notifications is not. High cohesion helps improve clarity, reduces duplication, and ensures that changes are easier to manage.
When systems have high cohesion and low coupling together, they become much easier to test because each part has a clear focus and fewer dependencies on other parts.