one way of decoupling components is through law of demeter. the concept states that a class should only call a method that belongs to itself(instance and class methods), method parameters, class and instance attributes and local references. there will be no call on the object's method that is being returned from a method call.
sample:
public void method(MyClass myClass)
{
myClass.getAnotherClass().thirdLevelMethod(); // violation
}
public void method(AnotherClass anotherClass)
{
anotherClass.thirdLevelMethod(); // correct
}
No comments:
Post a Comment