I'm reading through Fowler's refactoring book and am a bit confused about those two code smells.
"Message Chains" are calls like a.getB().getC().getValue()
.
"Middle Man" is a method like
class A
{
object getCValue()
{
return b.getCValue();
}
}
The way I understand the two section is that if you've got "Message Chains" you shorten them by introducing "Middle Men". And If you've got "Middle Men" you turn them into "Message Chains"...
Now obviously there has to be some limitation to this or you'd have a programmer's merry-go-round. At what point should I favor one over the other?
One is coupling the class to unrelated classes, the other is coupling the class to the structure. So in theory my approach would be to check if any given change reduces one kind of coupling more than it increases the other kind of coupling. But is one kind of coupling worse and should be weighed more? I.e. only add one class coupling if you can remove X structural couplings?