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

Member predicate MetricRefType::getLackOfCohesionCK

Gets the Chidamber-Kemerer lack of cohesion metric.

The aim of this metric is to try and 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 Chidamber and Kemerer method, this is measured as follows:

  • n1 = number of pairs of distinct methods in a reftype that do not have at least one commonly accessed field
  • n2 = number of pairs of distinct methods in a reftype that do have at least one commonly accessed field
  • lcom = ((n1 - n2)/2 max 0)

We divide by 2 because each pair (m1,m2) is counted twice in n1 and n2.

High values of lcom indicate a lack of cohesion.

float getLackOfCohesionCK()