How can LCOM be a rational number?

224 Views Asked by At

I've been busy with LCOM and the plugin Metrics in eclipse. In which I have to calculate manually the Lack of Cohesion of a class and compare it with the result of Metrics. But this plugin returns a LCOM of 1/3. How can LCOM be a rational number?

Because what I've been told is that

P := number of dissimilar method pairs

and

Q := number of similar method pairs.

And

if P>Q 
then LCOM = P - Q 
otherwise LCOM = 0

Is this equation correct? or is my plugin malfunctioning?

1

There are 1 best solutions below

0
On

There are several LCOM metrics which can be used so I can assume that you are not referring to the one used by that plugin. For example, these are the metrics used by ndepend and both are rational numbers:

  • LCOM = 1 – sum(MF) / M*F
  • LCOM_HS = (M – sum(MF) / F) (M-1)

Where:

  • M is the number of methods (both static and instance methods are counted, as well as constructors);
  • F is the number of instance variables;
  • MF is the number of methods accessing a particular instance field;
  • Sum(MF) is the sum of MF over all instance fields of the class.

(Source: ndepend.com)