O'Reilly logo

Refactoring Workbook by William C. Wake

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required