dimanche 10 avril 2022

LCOM is always 1 in JArchitect and Metrics Reloaded

So, I've been studying design patterns and in the context of the Single Responsibility Principle I tried to calculate the Lack of Cohesion of methods (LCOM) in Java using Metrics Reloaded and JArchitect. Both programs always calculate LCOM to be 1 although in some cases it's clearly not. Even the below standard example of low cohesion has an LCOM of 1 in these programs:

package com.StyleM;

public class NumberManipulator {
    private int number;

    public int numberValue() {
        return number;
    }
    public void addOne() {
        number++;
    }
    public void subtractOne() {
        number--;
    }
}

To my understanding the LCOM in this example should be 1-(3/4) = 0.25, because there are in total 4 methods (including the constructor) and 3 of them use the number field. What am I doing wrong?

Aucun commentaire:

Enregistrer un commentaire