Replace inheritance with delegation
Refactor | Replace Inheritance with Delegation
The Replace Inheritance With Delegation refactoring lets you remove a class from inheritance hierarchy, while preserving the functionality of the parent. IntelliJ IDEA creates a private inner class that inherits the former superclass or interface. Selected methods of the parent are invoked via the new inner class.
Select a class you want to refactor.
From the main menu or from the context menu, select Refactor | Replace Inheritance With Delegation.
In the dialog that opens, specify the parent object, the name of the inner class definition. Also, select the members of the parent class that will be delegated through the inner class, and getter options.
Preview and apply changes.
Before | After |
---|---|
|
|
Use this dialog to specify options for the Replace Inheritance With Delegation refactoring.
Item | Description |
---|---|
Replace with delegation inheritance from | Select here the parent object, inheritance to which will be replaced. |
Field name | Specify the name for the field of the new inner class. |
Inner class name | In this field specify the name for the inner class definition. |
Delegate members | In this area, select the members of the parent class, that will be delegated through the inner class. |
Generate getter for delegated component | Check this option to create a getter for the inner class. |
Thanks for your feedback!