Contents

  1. Cover Page
  2. About This E-Book
  3. Front End Paper
  4. Title Page
  5. Copyright Page
  6. Dedication Page
  7. Contents
  8. Foreword to the First Edition
  9. Preface
    1. What Is Refactoring?
    2. What’s in This Book?
    3. Who Should Read This Book?
    4. Building on a Foundation Laid by Others
    5. Acknowledgments
  10. Chapter 1 Refactoring: A First Example
    1. The Starting Point
    2. Comments on the Starting Program
    3. The First Step in Refactoring
    4. Decomposing the statement Function
    5. Status: Lots of Nested Functions
    6. Splitting the Phases of Calculation and Formatting
    7. Status: Separated into Two Files (and Phases)
    8. Reorganizing the Calculations by Type
    9. Status: Creating the Data with the Polymorphic Calculator
    10. Final Thoughts
  11. Chapter 2 Principles in Refactoring
    1. Defining Refactoring
    2. The Two Hats
    3. Why Should We Refactor?
    4. When Should We Refactor?
    5. Problems with Refactoring
    6. Refactoring, Architecture, and Yagni
    7. Refactoring and the Wider Software Development Process
    8. Refactoring and Performance
    9. Where Did Refactoring Come From?
    10. Automated Refactorings
    11. Going Further
  12. Chapter 3 Bad Smells in Code
    1. Mysterious Name
    2. Duplicated Code
    3. Long Function
    4. Long Parameter List
    5. Global Data
    6. Mutable Data
    7. Divergent Change
    8. Shotgun Surgery
    9. Feature Envy
    10. Data Clumps
    11. Primitive Obsession
    12. Repeated Switches
    13. Loops
    14. Lazy Element
    15. Speculative Generality
    16. Temporary Field
    17. Message Chains
    18. Middle Man
    19. Insider Trading
    20. Large Class
    21. Alternative Classes with Different Interfaces
    22. Data Class
    23. Refused Bequest
    24. Comments
  13. Chapter 4 Building Tests
    1. The Value of Self-Testing Code
    2. Sample Code to Test
    3. A First Test
    4. Add Another Test
    5. Modifying the Fixture
    6. Probing the Boundaries
    7. Much More Than This
  14. Chapter 5 Introducing the Catalog
    1. Format of the Refactorings
    2. The Choice of Refactorings
  15. Chapter 6 A First Set of Refactorings
    1. Extract Function
    2. Inline Function
    3. Extract Variable
    4. Inline Variable
    5. Change Function Declaration
    6. Encapsulate Variable
    7. Rename Variable
    8. Introduce Parameter Object
    9. Combine Functions into Class
    10. Combine Functions into Transform
    11. Split Phase
  16. Chapter 7 Encapsulation
    1. Encapsulate Record
    2. Encapsulate Collection
    3. Replace Primitive with Object
    4. Replace Temp with Query
    5. Extract Class
    6. Inline Class
    7. Hide Delegate
    8. Remove Middle Man
    9. Substitute Algorithm
  17. Chapter 8 Moving Features
    1. Move Function
    2. Move Field
    3. Move Statements into Function
    4. Move Statements to Callers
    5. Replace Inline Code with Function Call
    6. Slide Statements
    7. Split Loop
    8. Replace Loop with Pipeline
    9. Remove Dead Code
  18. Chapter 9 Organizing Data
    1. Split Variable
    2. Rename Field
    3. Replace Derived Variable with Query
    4. Change Reference to Value
    5. Change Value to Reference
  19. Chapter 10 Simplifying Conditional Logic
    1. Decompose Conditional
    2. Consolidate Conditional Expression
    3. Replace Nested Conditional with Guard Clauses
    4. Replace Conditional with Polymorphism
    5. Introduce Special Case
    6. Introduce Assertion
  20. Chapter 11 Refactoring APIs
    1. Separate Query from Modifier
    2. Parameterize Function
    3. Remove Flag Argument
    4. Preserve Whole Object
    5. Replace Parameter with Query
    6. Replace Query with Parameter
    7. Remove Setting Method
    8. Replace Constructor with Factory Function
    9. Replace Function with Command
    10. Replace Command with Function
  21. Chapter 12 Dealing with Inheritance
    1. Pull Up Method
    2. Pull Up Field
    3. Pull Up Constructor Body
    4. Push Down Method
    5. Push Down Field
    6. Replace Type Code with Subclasses
    7. Remove Subclass
    8. Extract Superclass
    9. Collapse Hierarchy
    10. Replace Subclass with Delegate
    11. Replace Superclass with Delegate
  22. Bibliography
  23. Index
  24. Back End Paper
  25. Code Snippets
  1. ii
  2. iii
  3. iv
  4. v
  5. vii
  6. viii
  7. ix
  8. x
  9. xi
  10. xii
  11. xiii
  12. xiv
  13. xv
  14. xvi
  15. xvii
  16. xviii
  17. xix
  18. 1
  19. 2
  20. 3
  21. 4
  22. 5
  23. 6
  24. 7
  25. 8
  26. 9
  27. 10
  28. 11
  29. 12
  30. 13
  31. 14
  32. 15
  33. 16
  34. 17
  35. 18
  36. 19
  37. 20
  38. 21
  39. 22
  40. 23
  41. 24
  42. 25
  43. 26
  44. 27
  45. 28
  46. 29
  47. 30
  48. 31
  49. 32
  50. 33
  51. 34
  52. 35
  53. 36
  54. 37
  55. 38
  56. 39
  57. 40
  58. 41
  59. 42
  60. 43
  61. 44
  62. 45
  63. 46
  64. 47
  65. 48
  66. 49
  67. 50
  68. 51
  69. 52
  70. 53
  71. 54
  72. 55
  73. 56
  74. 57
  75. 58
  76. 59
  77. 60
  78. 61
  79. 62
  80. 63
  81. 64
  82. 65
  83. 66
  84. 67
  85. 68
  86. 69
  87. 70
  88. 71
  89. 72
  90. 73
  91. 74
  92. 75
  93. 76
  94. 77
  95. 78
  96. 79
  97. 80
  98. 81
  99. 82
  100. 83
  101. 84
  102. 85
  103. 86
  104. 87
  105. 88
  106. 89
  107. 90
  108. 91
  109. 92
  110. 93
  111. 94
  112. 95
  113. 96
  114. 97
  115. 98
  116. 99
  117. 100
  118. 101
  119. 102
  120. 103
  121. 105
  122. 106
  123. 107
  124. 108
  125. 109
  126. 110
  127. 111
  128. 112
  129. 113
  130. 114
  131. 115
  132. 116
  133. 117
  134. 118
  135. 119
  136. 120
  137. 121
  138. 122
  139. 123
  140. 124
  141. 125
  142. 126
  143. 127
  144. 128
  145. 129
  146. 130
  147. 131
  148. 132
  149. 133
  150. 134
  151. 135
  152. 136
  153. 137
  154. 138
  155. 139
  156. 140
  157. 141
  158. 142
  159. 143
  160. 144
  161. 145
  162. 146
  163. 147
  164. 148
  165. 149
  166. 150
  167. 151
  168. 152
  169. 153
  170. 154
  171. 155
  172. 156
  173. 157
  174. 158
  175. 159
  176. 161
  177. 162
  178. 163
  179. 164
  180. 165
  181. 166
  182. 167
  183. 168
  184. 169
  185. 170
  186. 171
  187. 172
  188. 173
  189. 174
  190. 175
  191. 176
  192. 177
  193. 178
  194. 179
  195. 180
  196. 181
  197. 182
  198. 183
  199. 184
  200. 185
  201. 186
  202. 187
  203. 188
  204. 189
  205. 190
  206. 191
  207. 192
  208. 193
  209. 194
  210. 195
  211. 196
  212. 197
  213. 198
  214. 199
  215. 200
  216. 201
  217. 202
  218. 203
  219. 204
  220. 205
  221. 206
  222. 207
  223. 208
  224. 209
  225. 210
  226. 211
  227. 212
  228. 213
  229. 214
  230. 215
  231. 216
  232. 217
  233. 218
  234. 219
  235. 220
  236. 221
  237. 222
  238. 223
  239. 224
  240. 225
  241. 226
  242. 227
  243. 228
  244. 229
  245. 230
  246. 231
  247. 232
  248. 233
  249. 234
  250. 235
  251. 236
  252. 237
  253. 239
  254. 240
  255. 241
  256. 242
  257. 243
  258. 244
  259. 245
  260. 246
  261. 247
  262. 248
  263. 249
  264. 250
  265. 251
  266. 252
  267. 253
  268. 254
  269. 255
  270. 256
  271. 257
  272. 258
  273. 259
  274. 260
  275. 261
  276. 262
  277. 263
  278. 264
  279. 265
  280. 266
  281. 267
  282. 268
  283. 269
  284. 270
  285. 271
  286. 272
  287. 273
  288. 274
  289. 275
  290. 276
  291. 277
  292. 278
  293. 279
  294. 280
  295. 281
  296. 282
  297. 283
  298. 284
  299. 285
  300. 286
  301. 287
  302. 288
  303. 289
  304. 290
  305. 291
  306. 292
  307. 293
  308. 294
  309. 295
  310. 296
  311. 297
  312. 298
  313. 299
  314. 300
  315. 301
  316. 302
  317. 303
  318. 304
  319. 305
  320. 306
  321. 307
  322. 308
  323. 309
  324. 310
  325. 311
  326. 312
  327. 313
  328. 314
  329. 315
  330. 316
  331. 317
  332. 318
  333. 319
  334. 320
  335. 321
  336. 322
  337. 323
  338. 324
  339. 325
  340. 326
  341. 327
  342. 328
  343. 329
  344. 330
  345. 331
  346. 332
  347. 333
  348. 334
  349. 335
  350. 336
  351. 337
  352. 338
  353. 339
  354. 340
  355. 341
  356. 342
  357. 343
  358. 344
  359. 345
  360. 346
  361. 347
  362. 349
  363. 350
  364. 351
  365. 352
  366. 353
  367. 354
  368. 355
  369. 356
  370. 357
  371. 358
  372. 359
  373. 360
  374. 361
  375. 362
  376. 363
  377. 364
  378. 365
  379. 366
  380. 367
  381. 368
  382. 369
  383. 370
  384. 371
  385. 372
  386. 373
  387. 374
  388. 375
  389. 376
  390. 377
  391. 378
  392. 379
  393. 380
  394. 381
  395. 382
  396. 383
  397. 384
  398. 385
  399. 386
  400. 387
  401. 388
  402. 389
  403. 390
  404. 391
  405. 392
  406. 393
  407. 394
  408. 395
  409. 396
  410. 397
  411. 398
  412. 399
  413. 400
  414. 401
  415. 402
  416. 403
  417. 404
  418. 405
  419. 406
  420. 407
  421. 409
  422. 410
  423. 411
  424. 412
  425. 413
  426. 414
  427. 415
  428. 416
  429. 417
  430. 418
  431. 427
  432. 428