Remove middleman
The Remove Middleman refactoring lets you replace all calls to delegating methods in a class with the equivalent calls directly to the field delegated to. Additionally, you can automatically remove the classes delegating methods, which will now be unused.
This refactoring is useful if you have a class that simply forwards many of its method calls to objects of other classes, and you wish to simplify your design.
tip
This refactoring is also available from UML Class diagram.
This functionality relies on the Additional Java Refactorings plugin, which you need to install and enable.
Press to open settings and then select Plugins.
Open the Marketplace tab, find the Additional Java Refactorings plugin, and click Install (restart the IDE if prompted).
Open the class in question in the editor, and place the caret at the name of the delegating field.
On the main or context menu, select Refactor | Remove Middleman.
In the dialog that opens, select methods that you want to inline.
Before | After |
---|---|
|
|