Sunday, September 28, 2008

Refactoring (Part 1)

  • Replace Temp with Query
    Extract the expression into a method. Replace all reference to the temp with the new method. The new method can then be used in other methods.
  • Introduce Explaining Variable
    Put the result of the expression, or parts of the expression, in a temporary variable with a name that explains the purpose.
  • Split Temporary Variable
    Do not reuse the same temp variable, make a separate temporary variable for each assignment.
  • Remove Assignments to Parameters
    Function arguments should not be re-assigned inside the function.
  • Replace Method with Method Object
    Turn the method into its own object so that all the local variables become fields on that object. You can then decompose the method into other methods on the same object.
  • Substitute Algorithm
    Replace the body of the method with some new algorithm.

No comments: