Home Knowledge Base Middle Man

Middle Man is a code smell where a class delegates the majority of its method calls directly to another class without performing any meaningful logic of its own — functioning as a pure passthrough that adds a layer of indirection without adding abstraction, transformation, error handling, or any other value, violating the principle that every layer in a software architecture must earn its existence by contributing something to the system.

What Is Middle Man?

Middle Man is the opposite of Feature Envy — instead of a class's methods reaching into another class to use its data, Middle Man is a class that hands all requests to another class without doing any work itself:

# Middle Man: DepartmentManager adds zero value
class DepartmentManager:
    def __init__(self, department):
        self.department = department

    def get_employee_count(self):
        return self.department.get_employee_count()   # Pure delegation

    def get_budget(self):
        return self.department.get_budget()           # Pure delegation

    def add_employee(self, emp):
        return self.department.add_employee(emp)      # Pure delegation

    def get_head(self):
        return self.department.get_head()             # Pure delegation

# Better: Access department directly, or create a meaningful wrapper

Why Middle Man Matters

Middle Man vs. Legitimate Patterns

Not all delegation is Middle Man. Several legitimate patterns involve delegation:

PatternWhy It Is NOT Middle Man
FacadeSimplifies complex subsystem — aggregates multiple objects, provides a simpler interface
ProxyAdds access control, caching, logging, or lazy initialization
DecoratorAdds behavior before/after delegation
StrategySelects between different implementations based on context
AdapterTranslates between incompatible interfaces

The key distinction: legitimate delegation patterns add something (simplification, behavior, translation). Middle Man adds nothing.

Refactoring: Remove Middle Man

The standard fix is direct access — eliminate the passthrough:

1. For each Middle Man method, identify the underlying delegated method. 2. Replace all calls to the Middle Man method with direct calls to the underlying class. 3. Remove the Middle Man methods. 4. If the Middle Man class becomes empty, delete it.

When the delegation is partial (some methods delegate, some add logic), use Inline Method selectively — inline only the pure delegation methods and keep the methods that add value.

Tools

Middle Man is bureaucracy in code — an unnecessary administrative layer that routes requests without processing them, imposing comprehension overhead and maintenance burden on every developer who must navigate through it while contributing nothing to the correctness, reliability, or clarity of the system it inhabits.

middle mancode ai

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.