Refactoring

Supports Pillars:

Technical Excellence

Dependencies:

Test-Driven Development

Definition:

Refactoring is the process of improving the design of existing code without changing its externally observable behavior. In order to make big changes to the structure of the code, refactoring uses a quick succession of small, well-known steps that can each be verified as safe (functionally equivalent). Refactoring is most often done in the context of Test-Driven Development/Design where extensive tests and simple design make it easy to refactor safely.

Triggers:

We may apply a refactoring to:

  • improve readability of the code

  • reduce the cost of changing the code

  • improve performance

  • prepare for a specific future change

  • understand the design/document our new understanding

Forces:

forces that increase the cost of changing code:

duplication (at either code block or process/algorithm levels)

SOLID violations and other code smells

low coupling

short methods

no comments

simple design

coherent structure

forces that decrease the cost of changing the code:

refactoring now vs. later

small steps

automated tests

automated refactoring tools in the IDE

appropriate use of design patterns