Example
| Before | After |
|---|---|
// File Class.java public class Class extends SuperClass { public int varInt; public void openMethod() { ... } } // File SuperClass.java public abstract class SuperClass { public static final int CONSTANT=0; public abstract void openMethod(); public void secretMethod() { ... } } |
// File Class.java public class Class { public int varInt; private final MySuperClass superClass = new MySuperClass(); public SuperClass getSuperClass() { return superClass; } public void openMethod() { superClass.openMethod(); } private class MySuperClass extends SuperClass { public void openMethod() { ... } } } // File SuperClass.java UNCHANGED public abstract class SuperClass { public static final int CONSTANT=0; public abstract void openMethod(); public void secretMethod() { ... } } |
- Select the class.
- Open the Replace Inheritance With Delegation dialog box by choosing on the main menu, or on the context menu of the selection.
- In the Replace with delegation inheritance from field, select the parent object, inheritance to which will be replaced.
- Specify the name for the field of the new inner class.
- In the Inner class name field, specify the name for the inner class definition.
- In the Delegate members area, select the members of the parent class, that will be delegated through the inner class.
- To create a getter for the inner class, select the Generate getter for delegated component check box.
- To review the intended changes and make final corrections prior to the refactoring, click Preview. To apply the changes immediately, click Refactor.

