CodeQL library for Java/Kotlin
codeql/java-all 4.0.1-dev (changelog, source)
Search

Member predicate MetricRefType::getLackOfCohesionHS

Gets the Henderson-Sellers lack of cohesion metric.

The aim of this metric is to try to determine whether a class represents one abstraction (good) or multiple abstractions (bad). If a class represents multiple abstractions, it should be split up into multiple classes.

In the Henderson-Sellers method, this is measured as follows:

   M = set of methods in class
   F = set of fields in class
   r(f) = number of methods that access field f
   <r> = mean of r(f) over f in F

The lack of cohesion is then given by

  (<r> - |M|) / (1 - |M|)

We follow the Eclipse metrics plugin by restricting M to methods that access some field in the same class, and restrict F to fields that are read by methods in the same class.

High values of this metric indicate a lack of cohesion.

float getLackOfCohesionHS()