Extracting a Superclass
See Also
When you extract a superclass, the IDE does the following:
- You can preview the files that will be changed by clicking Preview in the Extract Interface dialog box.
If Preview is clicked, a list of the files to be modified is displayed in the Refactoring window.
If you do not want certain occurrences to be changed, you can clear the checkbox for that occurrence in the Refactoring window.
Double-clicking on an occurrence opens that file in the Source editor, and the caret is placed in the line containing the occurrence.
To extract a superclass:
- Open the class containing the methods or fields you want to move to the new superclass.
- In the Source editor, right-click in the file and choose Refactor > Extract Superclass.
The Extract Superclass dialog box opens.
- Type the name for your new superclass in the Superclass Name text field.
- Select the members you want to extract to the new superclass.
- (Optional) If you want to make a method abstract, select the Make Abstract checkbox for the method.
If you select this checkbox, the method will be declared in the superclass as an abstract method and overridden in the current class.
The method will be assigned the protected access modifier.
- If you click Refactor, the IDE applies
the changes automatically and skips the remaining steps. If you click Preview,
the Refactoring window displays the lines of code that will be changed. Review
the list and clear the checkbox of any code that you do not want changed. If the
class that you are pushing members from has multiple subclasses and you do not
want the members to be pushed to all of them, be sure to clear the checkboxes
for the corresponding subclasses. Click Do Refactoring to apply the selected changes.
- You should always perform a clean build after completing
any refactoring commands. You can do a clean build by right-clicking the project's
node in the Projects window and choosing Clean and Build Project.
- See Also
- Refactoring: Quick Reference
- Moving a Class Member to a Superclass
- Using a Supertype Where Possible
- Extracting an Interface
- Extracting a Method
- Renaming a Field or Method
- Undoing Refactoring Changes
Legal Notices