Foreword |
|
xiii | |
Preface |
|
xv | |
Acknowledgments |
|
xx | |
About the Authors |
|
xxii | |
|
Chapter 1 Refactoring, a First Example |
|
|
1 | (50) |
|
|
2 | (4) |
|
The First Step in Refactoring |
|
|
6 | (1) |
|
Decomposing and Redistributing the Statement Method |
|
|
7 | (25) |
|
Replacing the Conditional Logic on Price Code with Polymorphism |
|
|
32 | (18) |
|
|
50 | (1) |
|
Chapter 2 Principles in Refactoring |
|
|
51 | (22) |
|
Where Did Refactoring Come From? |
|
|
51 | (1) |
|
|
52 | (2) |
|
|
54 | (3) |
|
When Should You Refactor? |
|
|
57 | (3) |
|
|
60 | (1) |
|
What Do I Tell My Manager? |
|
|
61 | (1) |
|
Indirection and Refactoring |
|
|
61 | (2) |
|
Problems with Refactoring |
|
|
63 | (4) |
|
|
67 | (2) |
|
It Takes A While to Create Nothing |
|
|
69 | (1) |
|
Refactoring and Performance |
|
|
70 | (1) |
|
Optimizing a Payroll System |
|
|
71 | (2) |
|
Chapter 3 Bad Smells in Code |
|
|
73 | (14) |
|
|
74 | (1) |
|
|
74 | (2) |
|
|
76 | (1) |
|
|
76 | (1) |
|
|
77 | (1) |
|
|
78 | (1) |
|
|
78 | (1) |
|
|
79 | (1) |
|
|
79 | (1) |
|
|
80 | (1) |
|
Parallel Inheritance Hierarchies |
|
|
81 | (1) |
|
|
81 | (1) |
|
|
81 | (1) |
|
|
82 | (1) |
|
|
82 | (1) |
|
|
83 | (1) |
|
|
83 | (1) |
|
Alternative Classes with Different Interfaces |
|
|
83 | (1) |
|
|
84 | (1) |
|
|
84 | (1) |
|
|
84 | (1) |
|
|
85 | (1) |
|
|
86 | (1) |
|
|
86 | (1) |
|
|
86 | (1) |
|
|
87 | (10) |
|
The Value of Self-Testing Code |
|
|
87 | (1) |
|
The Test::Unit Testing Framework |
|
|
88 | (3) |
|
Developer and Quality Assurance Tests |
|
|
91 | (1) |
|
|
92 | (5) |
|
Chapter 5 Toward a Catalog of Refactorings |
|
|
97 | (4) |
|
Format of the Refactorings |
|
|
97 | (2) |
|
|
99 | (2) |
|
Chapter 6 Composing Methods |
|
|
101 | (66) |
|
|
102 | (6) |
|
|
108 | (2) |
|
|
110 | (1) |
|
|
111 | (3) |
|
|
114 | (3) |
|
Introduce Explaining Variable |
|
|
117 | (4) |
|
|
121 | (3) |
|
Remove Assignments to Parameters |
|
|
124 | (3) |
|
Replace Method with Method Object |
|
|
127 | (4) |
|
|
131 | (2) |
|
Replace Loop with Collection Closure Method |
|
|
133 | (2) |
|
Extract Surrounding Method |
|
|
135 | (4) |
|
Introduce Class Annotation |
|
|
139 | (3) |
|
Introduce Named Parameter |
|
|
142 | (5) |
|
|
147 | (3) |
|
Remove Unused Default Parameter |
|
|
150 | (2) |
|
Dynamic Method Definition |
|
|
152 | (6) |
|
Replace Dynamic Receptor with Dynamic Method Definition |
|
|
158 | (2) |
|
|
160 | (5) |
|
Move Eval from Runtime to Parse Time |
|
|
165 | (2) |
|
Chapter 7 Moving Features Between Objects |
|
|
167 | (20) |
|
|
167 | (5) |
|
|
172 | (3) |
|
|
175 | (4) |
|
|
179 | (2) |
|
|
181 | (4) |
|
|
185 | (2) |
|
Chapter 8 Organizing Data |
|
|
187 | (74) |
|
|
188 | (3) |
|
Replace Data Value with Object |
|
|
191 | (3) |
|
Change Value to Reference |
|
|
194 | (4) |
|
Change Reference to Value |
|
|
198 | (3) |
|
Replace Array with Object |
|
|
201 | (5) |
|
|
206 | (4) |
|
Change Unidirectional Association to Bidirectional |
|
|
210 | (3) |
|
Change Bidirectional Association to Unidirectional |
|
|
213 | (4) |
|
Replace Magic Number with Symbolic Constant |
|
|
217 | (2) |
|
|
219 | (5) |
|
Replace Record with Data Class |
|
|
224 | (1) |
|
Replace Type Code with Polymorphism |
|
|
225 | (7) |
|
Replace Type Code with Module Extension |
|
|
232 | (7) |
|
Replace Type Code with State/Strategy |
|
|
239 | (12) |
|
Replace Subclass with Fields |
|
|
251 | (4) |
|
Lazily Initialized Attribute |
|
|
255 | (2) |
|
Eagerly Initialized Attribute |
|
|
257 | (4) |
|
Chapter 9 Simplifying Conditional Expressions |
|
|
261 | (36) |
|
|
261 | (3) |
|
|
264 | (1) |
|
Consolidate Conditional Expression |
|
|
265 | (3) |
|
Consolidate Duplicate Conditional Fragments |
|
|
268 | (1) |
|
|
269 | (5) |
|
Replace Nested Conditional with Guard Clauses |
|
|
274 | (5) |
|
Replace Conditional with Polymorphism |
|
|
279 | (5) |
|
|
284 | (8) |
|
|
292 | (5) |
|
Chapter 10 Making Method Calls Simpler |
|
|
297 | (56) |
|
|
298 | (2) |
|
|
300 | (2) |
|
|
302 | (1) |
|
Separate Query from Modifier |
|
|
303 | (4) |
|
|
307 | (3) |
|
Replace Parameter with Explicit Methods |
|
|
310 | (3) |
|
|
313 | (4) |
|
Replace Parameter with Method |
|
|
317 | (3) |
|
Introduce Parameter Object |
|
|
320 | (4) |
|
|
324 | (3) |
|
|
327 | (1) |
|
Replace Constructor with Factory Method |
|
|
328 | (4) |
|
Replace Error Code with Exception |
|
|
332 | (5) |
|
Replace Exception with Test |
|
|
337 | (4) |
|
|
341 | (5) |
|
Introduce Expression Builder |
|
|
346 | (7) |
|
Chapter 11 Dealing with Generalization |
|
|
353 | (44) |
|
|
353 | (3) |
|
|
356 | (1) |
|
|
357 | (5) |
|
|
362 | (1) |
|
|
363 | (5) |
|
|
368 | (3) |
|
|
371 | (1) |
|
|
372 | (14) |
|
Replace Inheritance with Delegation |
|
|
386 | (3) |
|
Replace Delegation with Hierarchy |
|
|
389 | (3) |
|
Replace Abstract Superclass with Module |
|
|
392 | (5) |
|
Chapter 12 Big Refactorings |
|
|
397 | (20) |
|
|
397 | (1) |
|
Why Big Refactorings Are Important |
|
|
398 | (1) |
|
|
398 | (1) |
|
|
399 | (6) |
|
Convert Procedural Design to Objects |
|
|
405 | (1) |
|
Separate Domain from Presentation |
|
|
406 | (6) |
|
|
412 | (5) |
|
Chapter 13 Putting It All Together |
|
|
417 | (4) |
References |
|
421 | (2) |
Index |
|
423 | |