public class Foo {
/**
* This example will result in two violations.
*/
public void example(Bar b) {
// this method call is ok, as b is a parameter of "example"
C c = b.getC();
// this method call is a violation, as we are using c, which we got from B.
// We should ask b directly instead, e.g. "b.doItOnC();"
c.doIt();
// this is also a violation, just expressed differently as a method chain without temporary variables.
b.getC().doIt();
// a constructor call, not a method call.
D d = new D();
// this method call is ok, because we have create the new instance of D locally.
d.doSomethingElse();
}
}
Your list是一个参数吧,LawOfDemeter rule is to expect your parameter to be called directly by the method without using the object returned by the method (This object is not created inside the method), and then call the function of the object. You can refer to the above example modification. If it cannot be modified, then exclude this rule. This rule is a bit harsh.
LawOfDemeter
Your
list
是一个参数吧,LawOfDemeter
rule is to expect your parameter to be called directly by the method without using the object returned by the method (This object is not created inside the method), and then call the function of the object. You can refer to the above example modification.If it cannot be modified, then exclude this rule. This rule is a bit harsh.