Overview

Refactoring is done to improve the non-functional attributes of the software. It makes the code cleaner, more readable, and easier to maintain. It is a core practice of TDD and Extreme Programming.

Common Refactorings

  • Extract Method: Moving a piece of code into a new function.
  • Rename Variable: Using more descriptive names.
  • Simplify Conditional: Making complex if/else logic easier to follow.
  • Move Method: Moving a function to a more appropriate class.

Prerequisites

Refactoring should only be done when you have a solid suite of automated tests to ensure you haven't broken anything.

Related Terms