The description of the LOD that I saw (e.g. Wikipedia , C2 Wiki ) speak of non-calling methods. To quote Wikipedia:
The Demeter law for functions requires that the method M of an object O can only call methods of the following types of objects:
- About itself
- M parameters
- any objects created / created in M - O objects of a direct component
- a global variable accessible by O, in the area M
But what about accessing properties, variables, or enumerations? For example, given this:
class FirstClass {
public SecondClass GetRelatedClass() {
return new SecondClass();
}
public enum InnerEnum {
Violated,
NotViolated
}
}
class SecondClass {
public int Property {get; set;}
public string _variable = "Danny Demeter";
}
Are there any / all of these LOD violations? (Ignore direct access to the variable if you can ..)
void Violate(FirstClass first) {
SecondClass second = first.GetRelatedClass();
var x = second.Property;
var y = second._variable;
var z = FirstClass.InnerEnum.Violated;
}
( "" ), .