为什么缺乏方法的内聚性(LCOM)包括Getter和Setter

|| 我正在查看此处显示的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; }
}
由于每个getter和setter都不会访问“所有其他实例字段”,因此它的评分为0.94,是很糟糕的。 像这样计算
accessAverage - methodCount / 1 - methodCount

(2 - 17) / (1 - 17) = 0.94 (rounded)
我不了解这个指标,为什么它应该包含getter和setter?获取器和设置器将始终仅访问一个实例字段。     
已邀请:
这表明,如果您盲目地将每个软件指标都推到极致,那么它都有缺陷。 当您看到一个“内聚”类时,您就会知道。例如:
class HedgeHog_And_AfricanCountry
{

   private HedgeHog _hedgeHog;
   private Nation _africanNation;

   public ulong NumberOfQuills { get { return _hedgeHog.NumberOfQuills; } }
   public int CountOfAntsEatenToday { get { return _hedgeHog.AntsEatenToday.Count(); } }

   public decimal GrossDomesticProduct { get { return _africanNation.GDP; } }
   public ulong Population { get { return _africanNation.Population; } }
}
显然,这是一个内聚的类,因为它包含两个不需要相互关联的数据。 但是,尽管对于我们来说此类很明显是无内聚的,但是如何获得确定内聚的软件程序呢?如何判断上述类是非内聚的,但是不是吗?
class Customer
{
    public string FullName { get; set; }
    public Address PostalAddress { get; set; }
} 
他们提出的度量标准肯定可以检测到内聚,但也会带来误报。 如果您认为此指标很重要怎么办?您可以创建一个仅包含字段的\“ CustomerData \”类,以及一个将数据字段作为属性公开的\“ Customer \”类。
// This has no methods or getters, so gets a good cohesion value.
class CustomerData
{
    public string FullName;
    public Address PostalAddress;
}

// All of the getters and methods are on the same object
class Customer
{
   private CustomerData _customerData;
   public string FullName { get { return _customerData.FullName; } }
   // etc
}
但是,如果我正在玩这个游戏,我也可以将其应用于非粘性示例:
class Hedgehog_And_AfricanCountry_Data
{
   public Hedgehog _hedgehog;
   public AfricanNation _africanNation;
}

class Hedgehog_And_AfricanCountry
{
   private Hedgehog_And_AfricanCountry_Data _hedgehogAndAfricanCountryData;
   // etc;
}
确实,我认为最好是了解什么是内聚力以及为什么它是一个有价值的目标,但同时也要了解软件工具无法正确地衡量它。     

要回复问题请先登录注册