Lack of Cohesion in Methods and the LCOM4 metric

The Lack of Cohesion in Methods (LCOM) metric measures the cohesion of a class and it was first introduced in the Chidamber & Kemerer metrics suite in 1993. Since then, the metric was redefined and revised numerous times, with LCOM5 being the latest version.

Sonar incorporates version four of the metric, hence the LCOM4 naming. The metric measures the degree to which methods and fields within a class are related to one another, providing one or more components. To calculate the LCOM4 value, we have to determine how many connected groups of related methods and fields exist in a class:

  • LCOM4 = 1: The class is a solid component with all methods and fields related
  • LCOM4 > 1: The class can be split to ...

Get Sonar Code Quality Testing Essentials now with O’Reilly online learning.

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