Middle Man
A class that only delegates.
“Half the methods’ only work is delegating to another object.” – Fowler & Beck
Signs of Use (Symptoms)
- Class methods are one-liners that call the same method on a delegate.
- No logic added; pure pass-through.
Why it is bad (Consequences)
- Useless Indirection: Extra layer with no value.
- Overhead: Another class to maintain.
Why it happens (Root Cause)
Over-application of “Hide Delegate” to fix Message Chains.
When it might be okay (Exceptions)
- Decorator pattern (adds behavior).
- Facade pattern (simplifies a complex API).
Explanation
Problem
Manager has 20 methods, all of which just call Employee.doSomething().
The Flaw
Manager adds no value. Why not talk to Employee directly?
Real world analogy
A receptionist who only says “Please hold” and transfers every call, adding no screening or value.
Refactoring Solution
- Remove Middle Man: Client talks directly to the delegate.
- Inline Class.
Pros and Cons (of the Antipattern)
| Pros (Why people do it) | Cons (The price you pay) |
|---|---|
Comparison
- Related Antipatterns: Message Chains (opposite problem).
- Related Principles: KISS.
Code example
Typescript
Bad (The Antipattern)
Good (The Fix)