Move Method

Moving methods is generally easy. Moving a method allows you to place a method closer to the state it uses by moving it to the class which owns the related state.

To move a method:

  • Move the entire method definition and body into the new class.
  • Change any parameters which are part of the state of the new class to simply reference the instance variables or methods.
  • Introduce any necessary parameters because of state which belongs to the old class.
  • Rename the method if the new name no longer makes sense in the new context (for example, rename invite_user to invite once the method is moved to the User class).
  • Replace calls to the old method to calls to the new method. This may require introducing delegation or building an instance of the new class.