I am looking at the LCOM metric as shown here,
http://www.ndepend.com/Metrics.aspx
So we are saying a few things,
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
If I look at a class such as this,
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; }
}
It gets a bad score of 0.94 because each getter and setter doesn't access 'all of the other instance fields'.
It is calculated like this,
accessAverage - methodCount / 1 - methodCount
(2 - 17) / (1 - 17) = 0.94 (rounded)
I am not understanding this metric, why should it include getters and setters? A getter and setter will always only access one single instance field.
Assessment
thing, that's not really a class. It's just a dumb POCO (dumb
having a specific, non-derogatory meaning), a struct (or record in Pascal-like parlance.) It has no behavior (behavior typically represented by state relationships among methods.) Ergo, it is not a true class. It might be from a language POV, but not from a domain POV (which is what you really care for.) I either avoid collecting LCOM metrics in POJOS or structs, or ignore the results for them. LCOM is right - it is not a class. Simply use that info accordingly. – Dermatoplasty