Code Smell 67 - Middle Man

Code Smell 67 - Middle Man

Let's break Demeter's Law.

Problems

  • Unnecessary Indirection

  • Empty Classes

  • Readability

Solutions

  1. Remove Middle man.

Sample Code

Wrong

Detection

Same as its opposite smell, We can detect this small using parsing trees.

Tags

  • Coupling

  • Declarative

  • Readability

Conclusion

This is exactly the opposite to Message Chain. We make explicit the message chain.

Relations

More info

Credits

Photo by Dan Counsell on Unsplash


Whenever I have to think to understand what the code is doing, I ask myself if I can refactor the code to make that understanding more immediately apparent.

Martin Fowler



This article is part of the CodeSmell Series.