5.9. Lack of cohesion in methods

Cohesion is a central property of well-factored object-oriented code. Simply put, cohesion means that a class represents a single thing, a single abstraction. Cohesion is good—we want high cohesion——and the cohesion is a code smell.

The in methods part refers to the way we determine the degree of cohesion by looking at the commonalities between the methods of a class. Though there are many variations in how to calculate the lack of cohesion in methods, the common denominator is that they’re all based on the rough idea that perfect cohesion means that every field of a class is used by every method on that class.

In the context of unit tests and unit testing terminology, this could be expressed in such a way that ...

Get Effective Unit Testing now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.