Chapter 8Moving Features

So far, the refactorings have been about creating, removing, and renaming program elements. Another important part of refactoring is moving elements between contexts. I use Move Function (198) to move functions between classes and other modules. Fields can move too, with Move Field (207).

I also move individual statements around. I use Move Statements into Function (213) and Move Statements to Callers (217) to move them in or out of functions, as well as Slide Statements (223) to move them within a function. Sometimes, I can take some statements that match an existing function and use Replace Inline Code with Function Call (222) to remove the duplication.

Two refactorings I often do with loops are Split Loop (227), to ...

Get Refactoring: Improving the Design of Existing Code now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.