8th Light: Day 91

09 May 2016 . 8thlight . Comments #apprenticeship #8thlight #software #code-smells

Code smells: Middle man

If a class performs only one action, delegating work to another class, why does it exist at all? - sourcemaking.com

Middle men are code smells. Generally, writing extra code that acts as a mediator between different components of a system is a design smell – it adds unneeded bloat, additional steps to follow when reviewing code, and can be confusing.

However middle men can be good and even useful implementations in certain contexts. The adapter pattern is an example of a design pattern explicitly implemementing a middle man between two interfaces in order for them to communicate. Other instances where middle men may be useful are outdated APIs and interfacing with proprietary software.

It’s better to avoid the use of middle men, though are situations where middle men are needed as part of the design of a system.