What do high cohesion and low coupling mean in object-oriented design?
Interview preparation resource from Gate Smashers.
High cohesion means a class or module has closely related responsibilities that serve a focused purpose. Low coupling means classes or modules have minimal, well-defined dependencies on one another. Together, they make a system easier to understand, test, change, and reuse because changes are more likely to stay within the relevant module.
High cohesion
Cohesion describes how strongly the responsibilities within one class or module belong together. A highly cohesive class groups related data and behavior around a clear responsibility.
A cohesive class is not defined only by being small; its operations should support the same purpose. For example, a repository can focus on storing and retrieving a particular kind of data rather than also handling user-interface formatting or unrelated business rules.
Low coupling
Coupling describes the degree of dependency between classes or modules. Low coupling means a unit relies on other units through limited, clear contracts instead of their internal implementation details.
Low coupling does not mean that modules never interact. It means their necessary interactions are controlled, so a change in one module is less likely to require changes throughout the system.
Why they matter
High cohesion makes a unit easier to understand because its code addresses a focused concern. Low coupling reduces the ripple effect of changes because fewer units depend directly on one another.
Used together, these properties improve maintainability, testability, and reuse. A focused module with a narrow, stable interface can be tested or replaced more independently.
Design practices
Define meaningful class boundaries, keep related behavior and data together, and avoid mixing unrelated concerns in one class. Expose only the operations that clients need, while keeping implementation details encapsulated.
- Improve cohesion: Split a class when it contains unrelated responsibilities, such as persistence, presentation formatting, and business-rule processing.
- Reduce coupling: Depend on clear interfaces or abstractions where appropriate, and pass required dependencies explicitly rather than relying on global state.
- Watch for warning signs: Unrelated methods in one class can indicate low cohesion; frequent changes across several modules for one feature can indicate excessive coupling.
