Cohesion
When cohesion is high, it means that the methods and variables of the class are co-dependent and hang together as a logical whole.
An accumulation of instance variables shared between a few methods signifies low cohesion. Short parameter lists and small functions lead to many instance variables used by some of the methods in a class. When this happens, it almost always means that at least one other class is trying to get out of the larger class.
To ensure our functions are doing “one thing,” we need to ensure that the statements within our process are all at the same level of abstraction.
The first rule of functions is that they should be small. The second rule of parts is that they should be smaller than that.
The ideal number of arguments for a function is zero (niladic). Three arguments (triadic) should be avoided where possible. Next comes one (monadic), followed by two (dyadic). More than three (polyadic) require exceptional justification and shouldn’t be used.
If your function must change the state of something, have it change the shape of its owning object. Either your function should change the state of an object, or it should return some information about that object. Parts should either do something or answer something, but not both. Doing both often leads to confusion as another cause of low cohesion.
When classes lose cohesion, split them!
Separate the variables and methods into two or more classes such that the new classes are more cohesive.
–
[¹]: Robert Martin(2008):(Clean Code: A Handbook of Agile Software Craftsmanship)