IntelliJ IDEA 2024.2 Help

Pull members up, push members down

The Pull Members Up refactoring lets you move fields if two classes have the same field, or move methods if your subclasses have methods performing similar work. This helps you to get rid of duplicate code. You can also move class members to a superclass or an interface, or interface to superinterface.

The Push Members Down refactoring lets you clean up the class hierarchy by moving class members to a subclass or a subinterface. The members are then relocated into the direct subclasses/interfaces only. This improves internal class coherency.

  1. Select an item you want to pull up or push down.

  2. From the main or context menu, select Refactor | Pull Members Up or Refactor | Push Members Down.

  3. In the dialog that opens, depending on your refactoring, specify a destination object, members you want to move, and other additional information.

  4. Click Refactor.

Pull Members Up example

Before

After

// File Class.java public class Class extends SuperClass { public void publicMethod() { } public void hiddenMethod() { } } // File SuperClass.java public abstract class SuperClass { public abstract void publicMethod(); }
// File Class.java public class Class extends SuperClass { public void publicMethod() { } } // File SuperClass.java public abstract class SuperClass { public abstract void publicMethod(); public void hiddenMethod() { } }

Push Members Down example

Before

After

// File Class.java public class Class extends SuperClass { public void publicMethod() { } } // File SuperClass.java public abstract class SuperClass { public abstract void publicMethod(); public void hiddenMethod() { } }
// File Class.java public class Class extends SuperClass { public void publicMethod() { } public void hiddenMethod() { } } // File SuperClass.java public abstract class SuperClass { public abstract void publicMethod(); }
Last modified: 08 October 2024