我正在查看此处显示的 LCOM 指标,
http://www.ndepend.com/Metrics.aspx
所以我们要说几件事,
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; set; }
public string StartText { get; set; }
public decimal? SummaryWeight { get; set; }
}
它的得分为 0.94,因为每个 getter 和 setter 都不能访问“所有其他实例字段”。
是这样计算的,
accessAverage - methodCount / 1 - methodCount
(2 - 17) / (1 - 17) = 0.94 (rounded)
我不理解这个指标,为什么它应该包括 getter 和 setter?getter 和 setter 将始终只访问一个实例字段。