16.9. High Cohesion

Assign a responsibility so that cohesion remains high.

Solution

How to keep complexity manageable?

Problem

In terms of object design, cohesion (or more specifically, functional cohesion) is a measure of how strongly related and focused the responsibilities of an element are. An element with highly related responsibilities, and which does not do a tremendous amount of work, has high cohesion. These elements include classes, subsystems, and so on.

A class with low cohesion does many unrelated things, or does too much work. Such classes are undesirable; they suffer from the following problems:

  • hard to comprehend

  • hard to reuse

  • hard to maintain

  • delicate; constantly effected by change

Low cohesion classes often represent a very “large ...

Get Applying UML and Patterns: An Introduction to Object-Oriented Analysis and Design and the Unified Process, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.