O'Reilly logo

Sonar Code Quality Testing Essentials by Charalampos Arapidis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required