Named Refactorings
The noun definition of refactoring corresponds to the named refactorings. Examples include:
- "Move Method"
- "Rename Method"
- "Extract Interface"
Martin Fowler's classification of refactorings consists of six categories:
- composing methods
- moving features between objects
- organizing data
- simplifying conditional expressions
- making method calls simpler
- dealing with generalization
Page 193 (Table 7.2) has a huge list of specific examples!
Refactorings for Duplicate Code
"Extract Method" - any differences can be accounted for by a parameter.
Multiple similar or identical methods may be merged into one with parameters to capture any differences.
Inverses of Refactorings
| Method | Inverse |
|---|---|
| Replace Value with Reference | Change Reference to Value |
| Add Parameter | Remove Parameter |
| Pull Up Method | Pull Down Method |
| Extract Subclass | Collapse Hierarchy |
| Extract Class | Inline Class |
| Remove Middle Man | Hide Delegate |
| Replace Inheritance with Delegation | Replace Delegation with Inheritance |
Refactorings and Design Principles
Refactoring is widely recognized as a design activity or a step in the design process. This is because code smells indicate a violation of one or more design principles. There are thus refactorings for cleaning up specific code smells.
Page 197 has a table full of design principles and associated named refactorings for reference.