Question

The sonar documentation shows the following as a refactored code of LCOM4 = 1. But it seems to me that it should be 2, because there is no cohesion between getFullName and getFullAddress. What am I missing?

public class Client {

  public String firstname;
  public String lastname;
  public Address address;

  public String getFullName() {
    return firstname + " " + lastname;
  }

  public String getFullAddress() {
    return address.getFullAddress();
  }

}
Était-ce utile?

La solution

Seems you've found a documentation issue! According to Freddy Mallet, this isn't a great example of LCOM4 refactoring and will be fixed:

http://sonar.15.n6.nabble.com/Question-about-LCOM4-td5009876.html

Generally speaking, there are a handful of data structures that don't fit well into the LCOM4 algorithm, which is important to remember when making refactoring decisions. POJOs and concrete implementations of Template Method pattern are two examples that I have found to fall into this category.

In this specific case Mallet in the above link explains that this specific bean is granted LCOM4=1 because getFullAddress is considered a bean accessor, and bean accessors are excluded from the LCOM4 scoring.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top