Extract superclass
Last modified: 10 August 2022The Extract Superclass refactoring lets you either create a superclass based on an existing class or you can rename the original class so it becomes an implementation for the newly created superclass. In this case, IntelliJ IDEA changes all original class usages to use a superclass where possible.
Fields and methods in the original class can be moved to the superclass. Also for a method, you can transfer only the method declaration but not the implementation declaring the method as abstract in the superclass. As a result, you will have the superclass and the original class inherited from the superclass.
Open the class in the editor and from the main menu select Refactor | Extract | Superclass.
In the dialog that opens, specify a name for your class, location and class members that you want to include to form your superclass. Select the Make abstract checkbox to leave the method implementation within the current class, and declare it abstract in the extracted superclass. Click Refactor.
Example
Before | After |
---|---|
|
|
Thanks for your feedback!