Composing Methods

Simplifying methods and removing duplication.

Table of Contents

  • Extract Method: Turn a code fragment into a method with a name that explains the purpose of the method.
  • Inline Method: Put the method’s body into the body of its callers and remove the method.
  • Extract Variable: Put the result of an expression, or parts of it, into a temporary variable with a name that explains the purpose.
  • Inline Temp: Replace references to a temporary variable with the expression itself.
  • Replace Temp with Query: Move the entire expression not into a variable, but into a method.
  • Split Temporary Variable: Use a different temporary variable for each assignment if a variable is assigned to more than once.