Extracting a Superclass

See Also

When you extract a superclass, the IDE does the following:

To extract a superclass:

  1. Open the class containing the methods or fields you want to move to the new superclass.
  2. In the Source editor, right-click in the file and choose Refactor > Extract Superclass.

    The Extract Superclass dialog box opens.

  3. Type the name for your new superclass in the Superclass Name text field.
  4. Select the members you want to extract to the new superclass.
  5. (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.
  6. 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.
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