-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Refactoring in Java
By :

The middle man is a code smell that occurs when we have a class or, in general, an object that does only one thing, and that thing is... delegating the work to someone else. We are not suggesting that a class should have only one method to be considered a "middle man". Rather, each of its methods should only invoke others. So, the question arises spontaneously: why keep a class in our codebase that does nothing? In fact, there is (almost never) a reason. Let’s delete this class or method and ensure that the client calls the “destination” directly. This way, we will eliminate unnecessary complexity and ensure that, when we modify or add features to the destination objects, we are not forced to also modify our middle man.
To give an example, suppose we have a class structured like this:
public class Person { private Address address; public City getCity() { ...