我正在查看此处显示的LCOM指标,
http://www.ndepend.com/Metrics.aspx
所以我们说了几件事,
Run Code Online (Sandbox Code Playgroud)1) A class is utterly cohesive if all its methods use all its instance fields 2) Both static and instance methods are counted, it includes also constructors, properties getters/setters, events add/remove methods
如果我看一下这样的课,
public class Assessment
{
public int StartMetres { get; set; }
public int EndMetres { get; set; }
public decimal? NumericResponse { get; set; }
public string FreeResponse { get; set; }
public string Responsetype { get; set; }
public string ItemResponseDescription { get; …Run Code Online (Sandbox Code Playgroud) 最近,我在计算LCOM4的过程中遇到了一个问题,这个度量用于查找类的方法和属性是如何隐藏的.
LCOM4是"计算方法凝聚力缺乏的第四种方法",Hitz和Montazeri对此进行了描述(http://www.isys.uni-klu.ac.at/PDF/1995-0043-MHBM.pdf)并且目前是定义一个班级拥有多少责任的最佳方式.
我会尝试不使用特定的开发语言,因为我的问题是针对所有OOP语言.
让我基本上用默认算法解释它对不知道的人的作用:
Class Foo {
property a,b
function f1() { this.a = 1 }
function f2() { this.f1() }
function f3() { this.b = 3 }
}
Run Code Online (Sandbox Code Playgroud)
这个类有两个流程:
所以Foo的LCOM4是2.
让我们改变例如函数f2()来共享属性b.
Class Foo {
property a,b
function f1() { this.a = 1 }
function f2() { this.f1(); this.b = 1 }
function f3() { this.b = 3 }
}
Run Code Online (Sandbox Code Playgroud)
现在这个类只有一个流程:
这意味着Foo的LCOM4现在为1.
LCOM4 = 0或LCOM4 = 1表示班里有没有或只有1名责任,这是每个人都必须要为自己的班级,因为他们尊重小号的小号奥利德良好做法.
您可以在此处找到有关图表的更多信息:http: …
SonarQube 4.2版本是否提供LCOM指标?
我需要在我的报告中添加此指标,但我看不到它可用.
请告诉我是否有任何特定的jar来添加此指标.该指标可在Sonar 3.7中找到
任何帮助表示赞赏.
谢谢,Sreekanth