Interlude 1. Smells and Refactorings
The smells (along with the refactorings commonly used to fix them) from Martin Fowler's book Refactoring are listed in Table I-1, and the refactorings are listed in Table I-2.
| INTERLUDE I1.1 |
Tally. Put a tally mark by each refactoring for each time a smell references it. | | INTERLUDE I1.2 |
Refactorings that Fix the Most Smells. Which refactorings fix the most smells?
See Appendix A for solution.
| | INTERLUDE I1.3 |
Refactorings Not Mentioned. Which refactorings aren't mentioned by any of the smells? Why not?
See Appendix A for solutions.
| | INTERLUDE I1.4 |
Other Smells. Does this list suggest any other smells you might want to be aware of?
See Appendix A for solutions.
|
Table I.1. Smells and Their Associated Refactorings (from Fowler's Refactoring, back cover)|
Alternative Classes with Different Interfaces | Rename Method, Move Method | Comments | Extract Method, Introduce Assertion | Data Class | Move Method, Encapsulate Field, Encapsulate Collection | Data Clump | Extract Class, Introduc6e Parameter Object, Preserve Whole Object | Divergent Change | Extract Class | Duplicated Code | Extract Method, Extract Class, Pull Up Method, Form Template Method | Feature Envy | Move Method, Move Field, Extract Method | Inappropriate Intimacy | Move Method, Move Field, Change Bidirectional Association to Unidirectional, Replace Inheritance with Delegation, Hide Delegate | Incomplete Library Class | Introduce Foreign Method, Introduce Local Extension | Large Class | Extract Class, Extract Subclass, Extract Interface, Replace Data Value with Object | Lazy Class | Inline Class, Collapse Hierarchy | Long Method | Extract Method, Replace Temp with Query, Replace Method with Method Object, Decompose Conditional | Long Parameter List | Replace Parameter with Method, Introduce Parameter Object, Preserve Whole Object | Message Chains | Hide Delegate | Middle Man | Remove Middle Man, Inline Method, Replace Delegation with Inheritance | Parallel Inheritance Hierarchies | Move Method, Move Field | Primitive Obsession | Replace Data Value with Object, Extract Class, Introduce Parameter Object, Replace Array with Object, Replace Type Code with Class, Replace Type Code with Subclasses, Replace Type Code with State/Strategy | Refused Bequest | Replace Inheritance with Delegation | Shotgun Surgery | Move Method, Move Field, Inline Class | Speculative Generality | Collapse Hierarchy, Inline Class, Remove Parameter, Rename Method | Switch Statements | Replace Conditional with Polymorphism, Replace Type Code with Subclasses, Replace Type Code with State/Strategy, Replace Parameter with Explicit Methods, Introduce Null Object | Temporary Field | Extract Class, Introduce Null Object |
Table I.2. Refactorings (from Fowler, Refactoring, inside front cover)Add Parameter | Pull Up Constructor Body | Change Bidirectional Association to Unidirectional | Pull Up Field | Change Reference to Value | Pull Up Method | Change Unidirectional Association to Bidirectional | Push Down Field | Change Value to Reference | Push Down Method | Collapse Hierarchy | Remove Assignment to Parameters | Consolidate Conditional Expression | Remove Control Flag | Consolidate Duplicate Conditional Expression | Remove Middle Man | Convert Procedural Design to Objects | Remove Parameter | Decompose Conditional | Remove Setting Method | Duplicate Observed Data | Rename Method | Encapsulate Collection | Replace Array with Object | Encapsulate Downcast | Replace Conditional with Polymorphism | Encapsulate Field | Replace Constructor with Factory Method | Extract Class | Replace Data Value with Object | Extract Hierarchy | Replace Delegation with Inheritance | Extract Interface | Replace Error Code with Exception | Extract Method | Replace Exception with Test | Extract Subclass | Replace Inheritance with Delegation | Extract Superclass | Replace Magic Number with Symbolic Constant | Form Template Method | Replace Method with Method Object | Hide Delegate | Replace Nested Conditional with Guard Clause | Hide Method | Replace Parameter with Explicit Methods | Inline Class | Replace Parameter with Method | Inline Method | Replace Record with Data Class | Inline Temp | Replace Subclass with Fields | Introduce Assertion | Replace Temp with Query | Introduce Explaining Variable | Replace Type Code with Class | Introduce Foreign Method | Replace Type Code with State/Strategy | Introduce Local Extension | Replace Type Code with Subclasses | Introduce Null Object | Self Encapsulate Field | Introduce Parameter Object | Separate Domain from Presentation | Move Field | Split Temporary Variable | Move Method | Substitute Algorithm | Parameterize Method | Tease Apart Inheritance | Preserve Whole Object | |
 |