A collection of techniques which might help developers to refactor the code. The code samples were implemented using JavaScript as a programming language. For testing I used Mocha.
- Change Function Declaration
- Combine Functions into Class
- Combine Functions into Transform
- Introduce Parameter Object
- Rename variable
- Encapsulate Collection
- Encapsulate Record
- Encapsulate Variable
- Hide Delegate
- Remove Middle Man
- Replace Primitive with Object
- Replace Temp with Query
- Substitute Algorithm
- Move Function
- Move Field
- Move statements into Function
- Move statements to Callers
- Remove Dead Code
- Replace Inline Code with Function Call
- Replace loop with pipeline
- Slide statements
- Split loop
- Change Reference to Value
- Change Value to Reference
- Rename Field
- Replace Derived Variable with Query
- Split Variable
- Consolidate Conditional Expression
- Decompose Conditional
- Introduce Special Case
- Introduce Assertion
- Replace Nested Conditional with Guard Clauses
- Replace Conditional with Polymorphism
- Separate Query from Modifier
- Parameterize Function
- Preserve Whole Object
- Remove Flag Argument
- Remove Setting Method
- Replace Parameter with Query
- Replace Query with Parameter
- Replace Constructor with Factory Function
- Replace Function with Command
- Replace Command with Function
- Collapse Hierarchy
- Extras Superclass
- Pull Up Method
- Pull Up Field
- Push Down Method
- Push Down Field
- Remove Subclass
- Replace Type Code with Subclasses
- Replace Subclass with Delegate
- Replace Superclass with Delegate
Book: Refactoring Improving the Design of Existing Code by Martin Fowler, with Kent Beck