lack of cohesion in methods (LCOM)
So-called software metrics, which quantify different properties of software products and processes, are used to measure software products. When measuring software, an object-oriented metric takes into account the grouping of data structures and the methods applicable to them to form an object, its relationships to other objects and the general structural features of object-oriented programming.
The Lack of Cohesion in Methods (LCOM) metric is a measure of the cohesion - i.e. the cohesion - of methods in the class under consideration. Other object-oriented software metrics include Weighted Methods for Class(WMC), Response for a Class( RFC), Coupling Between Objects( CBO), Depth of Inheritance Tree( DIT), and Number of Children ( NOC).
LCOM definition: LCOM is equal to the pairs of methods without gm. Instv. Minus the pairs of methods with gm. Instv. gm. Instv. is the common instance variable.
It is important with this method to make sure that pairs of methods are considered in each case. Since a negative value of LCOM is nonsensical, LCOM=0 is set if the subtraction results in a negative value.
According to the illustration below, a class A with 3 methods m1(), m2() and m3() is given, each of which operates on certain instance variables.
Example class with methods and instance variables:
Pairs: m1/m3, m1/m2, m2/m3, with m1/m2 as common instance variable c.
Pairs of methods without gm. Instv. = 1+0+1, pairs of methods with gm. Instv. = 0+1+0
LCOM(A) = 2-1 = 1.
Application: Approach to checking the encapsulation of a class. This from the consideration that a high value of LCOM indicates poor encapsulation, since obviously many methods operate on disjoint attribute sets.