RSS Feed for This PostCurrent Article

Java: Refactoring Methods

Here are the guidelines that we follow to refactor the methods in one of the legacy Java application, simplified from Martin Fowler refactoring book.

  • Rename a method to server its purpose
  • Add a parameter to the method if it is required
  • Remove a parameter if it is not required
  • Separate query from modifier and let each method does it own function
  • Parametize method to consolidate different methods into one
  • Replace parameter with method so that your don’t use parameter to determine the execution
  • Preserve whole object to pass it as parameter
  • Replace a parameter with a method
  • Introduce parameter object to group parameters together
  • Remove setter method if it is not used
  • Hide the method if it is not used
  • Replace constructor with factory method
  • Encapsulate downcast. Now with JDK 5 and above we can make use of generic features
  • Replace error code with exception.
  • Replace exception with tests.


Trackback URL


Sorry, comments for this entry are closed at this time.