Appendix A. Answers to Selected Questions

Chapter 2. The Refactoring Cycle

Exercise 1. Small Steps

Most refactorings reflect this attitude (safety even in mid-refactoring). Consider our Encapsulate Field example. Even this simple program compiled three times. Or look at Extract Method: rather than simply cutting the old code and moving it, Fowler's catalog suggests copying the code and adjusting it before deleting the old version.

Exercise 2. Simple Design

A.

  1. Passes all tests. “If it doesn't have to work, I can give it to you right now.”

  2. Communicates. This makes an appeal to our intuition about future readers of our code (including ourselves).

  3. No duplication. Duplicate code is asking for trouble; it's too vulnerable to changes in one place but not in ...

Get Refactoring Workbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.