🔸 TL;DR
▪️ Delegation is good… until your class just forwards calls.
▪️ If half the methods simply delegate, it’s time to remove the middle man.
▪️ Few pass-throughs? Inline the calls.
▪️ Need extra behavior? Replace superclass with delegate and fold logic into the real object.
🔸 WHAT IS THE “MIDDLE MAN”?
▪️ A class/interface that mostly forwards requests to another class.
▪️ Adds indirection, slows changes, and hides the real responsibility.
▪️ Common after quick wrappers, rushed abstractions, or overusing patterns. 😵💫
🔸 SIGNS IT’S TIME TO CHANGE
▪️ Half (or more) of the methods just delegate elsewhere.
▪️ You open the class and find almost no real logic.
▪️ Every feature requires hopping across multiple thin layers. 🪜
🔸 HOW TO FIX IT
▪️ Inline Function when only a few methods delegate.
▪️ Remove Middle Man if most methods are pass-throughs—call the real collaborator directly.
▪️ Replace Superclass with Delegate when extra behavior is needed: delegate to the real object and implement behavior where it actually belongs.
▪️ Simplify call chains and make responsibilities explicit. ✅
🔸 TAKEAWAYS
▪️ Delegation ≠ value if it adds zero behavior.
▪️ Prefer direct, clear collaborations over ceremonial layers.
▪️ Refactor toward the object that truly owns the behavior. 🚀
#CleanCode #Refactoring #CodeSmells #DesignPatterns #OOP #SoftwareEngineering #Java #Maintainability #Readability #DevBestPractices
Go further with Java certification:
Java👇
Spring👇
SpringBook👇