Skip to main content

Tight Class Cohesion

Measures how well the methods of a class are related to each other.

A cohesive class performs one function. A non-cohesive class performs two or more unrelated functions. A non-cohesive class may need to be restructured into two or more smaller classes.

Calculated as the ratio between the actual number of visible directly connected methods in a class divided by the number of maximal possible number of connections between the visible methods of a class. Two visible methods are directly connected, if they are accessing the same instance variables of the class.

A recommended TCC is 0.33 or more.

Config example​

dart_code_metrics:
...
metrics:
...
tight-class-cohesion: 0.33
...