|
Hi
I am really confused on how Sonar computes the Response for Class metric :(
Given the following two dummy classes, what's the expected RFC value for each class? Sonar shows me RFC = 6 for each class... but based on the definition:" The response set of a class is a set of methods that can potentially be executed in response to a message received by an object of that class. RFC is simply the number of methods in the set." , when I manually try to compute the metrics I come up with an RFC of 3 for each class. Am I missing something?
public class ClassA
{
private ClassB classB = new ClassB();
public void doSomething(){
System.out.println ( "doSomething");
}
public void doSomethingBasedOnClassB(){
System.out.println (classB.toString());
}
}public class ClassB
{
private ClassA classA = new ClassA();
public void doSomethingBasedOneClassA(){
System.out.println (classA.toString());
}
public String toString(){
return "classB";
}
}Regards |
|
Hi Patroklos,
Let's take the example of ClassA, here is the list of methods that lead to this RFC value
|
|
Thanks a lot Freddy.
I missed the fact that we count methods and constructors of target class. But I have another two examples that confuse me even more!!
For the Class Country Sonar reports an RFC of 2 !! public class Country {
private String code;
private double vat;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public double getVat() {
return vat;
}
public void setVat(double vat) {
this.vat = vat;
}
}But for the Class Employee I get an RFC of 4 !! public class Employee {
private double salary;
private double bonus;
private int yearsInManagement;
private int yearsInSales; public double getTotalEarnings() {
return salary + bonus ;
}
public int getTotalYearsOfService() {
return yearsInManagement + yearsInSales ;
}
}Sorry for repeating my self but I'm trying to figure out how to minimize this metric for some classes but I can't even understand how it's computed :(
Regards Patroklos 2012/6/27 Freddy Mallet <[hidden email]> Hi Patroklos, |
|
Hi Patroklos,
And indeed this is another special case : the "standard" getter/setter methods don't increment the RFC metric. But in that case I expect to get 1 for class Country and 3 for class Employee (as the getTotalEarnings and getTotalYearsOfService are not getters/setters).
Could you send the bytecode of those two classes, which java compiler are you using ? Thanks Freddy -----
Sonar for Continuous Inspection On Wed, Jun 27, 2012 at 6:35 PM, Papapetrou P.Patroklos <[hidden email]> wrote: Thanks a lot Freddy. |
|
Hi Freddy
I am using Oracle's JDK 1.6.0_31 and I'm attaching the files you requested.
Thanks a lot Patroklos 2012/7/2 Freddy Mallet <[hidden email]> Hi Patroklos, --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
Hi Patroklos,
In this case this is still a side effect of the automatic creation of a default constructor by the compiler. Indeed this default constructor also contains a call to the constructor of the Object class and so we do have two called methods/constructors.
In any case, FYI we plan to still improve the way the LCOM4 metric is computed in order to be able to automatically fire some violations as soon as this value is greater than 1 but that's another story for this RFC value. Indeed, I don't see anyway to clearly define a limit to this RFC value and so the usability of this metric seems to be very low. That's why we've decided in the upcoming 3.2 version of Sonar to remove this metric from the default project dashboard.
Kind regards, Freddy
-----
Sonar for Continuous Inspection On Tue, Jul 3, 2012 at 12:39 PM, Papapetrou P.Patroklos <[hidden email]> wrote: Hi Freddy |
|
Hi Freddy
Thanks a lot for clarifying both metrics and their "future" in Sonar :)
I agree that LCOM4 is much more important and meaningful. I think though that RFC is an indicator ( among others ) of complexity if evaluated with other metrics :)
Regards Patroklos
2012/7/3 Freddy Mallet <[hidden email]> Hi Patroklos, |
| Powered by Nabble | Edit this page |
