Refactoring Rename Method


The name of a method does not explain what the method does.


Rename the method.
Rename Method - Before
Rename Method - After

Why Refactor

Perhaps a method was poorly named from the very beginning – for example, someone created the method in a rush and did not give proper care to naming it well.

Or perhaps the method was well named at first but as its functionality grew, the method name stopped being a good descriptor.


  • Code readability. Try to give the new method a name that reflects what it does. Something like createOrder(), renderCustomerInfo(), etc.

How to Refactor

  1. See whether the method is defined in a superclass or subclass. If so, you must repeat all steps in these classes too.

  2. The next method is important for maintaining the functionality of the program during the refactoring process. Create a new method with a new name. Copy the code of the old method to it. Delete all the code in the old method and, instead of it, insert a call for the new method.

  3. Find all references to the old method and replace them with references to the new one.

  4. Delete the old method. If the old method is part of a public interface, do not perform this step. Instead, mark the old method as deprecated.

Tired of reading?

No wonder, there are 7 hours worth of the text on this website.

Try out something different. We've just launched the interactive learning course on refactoring. It has more content and much more fun than a boring text.

Learn more...

Live Example

First time here? No worries!

Everything is quite simple. This example is like video (but much cooler):

  1. After pressing the Play button, you will see floating messages, which will guide you through the example. You can proceed by clicking on them.
  2. You can fast-forward or return to previous steps by pressing arrow buttons on the left.
  3. Also, you can take a look at the code diff window, which will show what has changed in code during the example ()
  4. To check the code for errors, you can press "Compile and test" button ()