ISBN-10:
0321109295
ISBN-13:
9780321109293
Pub. Date:
09/10/2003
Publisher:
Addison-Wesley
Refactoring Workbook / Edition 1

Refactoring Workbook / Edition 1

by William C. Wake

Paperback

Current price is , Original price is $39.99. You

Temporarily Out of Stock Online

Please check back later for updated availability.

Overview

As a programmer, you need to be able to recognize and improve problematic code, so the program remains in a working state throughout the software lifecycle. Refactoring-the art of improving the design of existing code safely-provides an efficient, reliable system for bringing order to the chaos, and one that keeps the surprises to a minimum! Refactoring can be difficult to learn, but Refactoring Workbook, by consultant William C. Wake, presents the material in a easy-learning format that makes learning enjoyable and effective.

For many, the obstacle to learning refactoring is in identifying the "smells"—the potential problem areas-found in code. Instead of having you read about the smells, Refactoring Workbook makes sure you understand them. You'll solve a carefully assembled series of problems, and you'll find yourself learning at a deeper level and arriving at a few insights of your own. Wake uses the workbook method—a learning-focused approach that forces you to apply the techniques presented in the book-in the rest of the book. This approach helps you learn and apply the most important refactoring techniques to your code and, as a side benefit, helps you to think more about creating great code even when you're not refactoring.

Refactoring Workbook provides user-friendly references such as:

  • A handy, quick-reference "smell finder"
  • A standard format for describing smells
  • Appendices showing key refactorings
  • A listing of Java™ tools that support refactoring

This book is intended for programmers with a knowledge of Java, though a C# or C++ programmer with a basic understanding of Java would also be able to follow and learn from the examples. It can be used as a companion to Martin Fowler's Refactoring (also from Addison-Wesley Professional), which provides step-by-step instructions for many refactorings.

Product Details

ISBN-13: 9780321109293
Publisher: Addison-Wesley
Publication date: 09/10/2003
Edition description: First Edition
Pages: 224
Product dimensions: 7.30(w) x 8.90(h) x 0.70(d)

About the Author

WILLIAM C. WAKE is an independent software consultant, coach, and trainer who has been programming for over 20 years. He has previously worked for Capital One Financial, MCI/WorldCom, VTLS, Inc, and others. He is the author of Extreme Programming Explored, also available from Addison-Wesley Professional.

Read an Excerpt

PrefaceWhat Is Refactoring?

Refactoring is the art of improving the design of existing code. Refactoring provides us with ways to recognize problematic code and gives us recipes for improving it.

What Are the Goals of This Book?

This book is a workbook designed to help you

  • Practice recognizing the most important smells (i.e., problems)
  • Apply the most important refactoring techniques
  • Think more about how to create great code
  • Have fun!

To a smaller extent, this book is a reference book with

  • A smell finder inside the covers
  • A standard format for describing smells
  • An appendix listing Java tools supporting refactoring
  • An appendix showing key refactorings
Who Is This Book For?

Refactoring being a technique for code, this book then is especially intended for practicing programmers who write and maintain code.

Students can also benefit from refactoring, although I'd expect they'd see the value only after they've had a chance to develop medium-sized or larger programs or had to work in teams (this probably applies to juniors, seniors, and graduate students).

What Background Do You Need?

It would be helpful to have the book, Refactoring: Improving the Design of Existing Code, by Martin Fowler et al. for its catalog of refactorings. (You can read my book and Refactoring at the same time.) Martin and his colleagues have worked out step-by-step instructions for many refactorings, and I will not repeat those in this book. Furthermore, they've provided a fully worked-out example, along with a lot of good discussion and background material. Someone determined to get through this book without that one could probably do it, but I wouldn't recommend it.

The examples in this book are written in Java. This is not because it's the easiest language to refactor, but because it's popular, and the best Java development environments provide automated refactoring support. A C# or C++ programmer has enough reading knowledge of Java to make sense of most of the questions. However, in later parts of the book, you will modify, test, and run larger programs, and this could be problematic for programmers using languages other than Java.

The book Design Patterns, by Gamma et al., describes patterns as "targets for refactoring." It would be helpful to have some familiarity with the ideas in that book because I freely refer to the patterns it mentions. If you're not yet familiar with Design Patterns, let me recommend Steve Metsker's book, Design Patterns Java Workbook, as well.

How to Use This Book

Solving a problem is more challenging than recognizing a solution. There are answers to some problems in the back of the book, but you'll learn more if you try the problems before peeking at the answers. If you work through the problems, you'll probably even find that you disagree with me on some answers. That will be more fun for all of us than if you just look at my answers and nod.

I think it's more fun to work with others (either a partner or in a small group), but I recognize that isn't always possible.

The later (longer) examples need to be done at a computer. Looking for problems, and figuring out how to solve them, is different when you're looking at a program in your environment.

Table of Contents



Preface.


1. Roadmap.

Overview. Section 1: Smells within Classes. Section 2: Smells between Classes. Section 3: Programs to Refactor. A Word on the Challenges.

I. SMELLS WITHIN CLASSES.


2. The Refactoring Cycle.

What Is Refactoring? Smells Are Problems. The Refactoring Cycle. When Are We Done? Inside a Refactoring. Challenges. Conclusion.


3. Measured Smells.

Smells Covered. Comments. Long Method. Large Class. Long Parameter List. More Challenges. Conclusion.


Interlude 1. Smells and Refactorings.

4. Names.

Smells Covered. Type Embedded in Name (Including Hungarian). Uncommunicative Name. Inconsistent Names.


5. Unnecessary Complexity.

Smells Covered. Dead Code. Speculative Generality.


Interlude 2. Inverses.

6. Duplication.

Smells Covered. Magic Number. Duplicated Code. Alternative Classes with Different Interfaces. Challenges.


7. Conditional Logic.

Smells Covered. Null Check. Complicated Boolean Expression. Special Case. Simulated Inheritance (Switch Statement).


Interlude 3. Design Patterns.

II. SMELLS BETWEEN CLASSES.


8. Data.

Smells Covered. Primitive Obsession. Data Class. Data Clump. Temporary Field.


9. Inheritance.

Smells Covered. Refused Bequest. Inappropriate Intimacy (Subclass Form). Lazy Class.


10. Responsibility.

Smells Covered. Feature Envy. Inappropriate Intimacy (General Form). Message Chains. Middle Man. Challenges.


11. Accommodating Change.

Smells Covered. Divergent Change. Shotgun Surgery. Parallel Inheritance Hierarchies. Combinatorial Explosion.


12. Library Classes.

Smells Covered. Incomplete Library Class. Challenges.


Interlude 4. Gen-A-Refactoring.

III. PROGRAMS TO REFACTOR.


13. A Database Example.

Course.java (Online at www.xp123.com/rwb). Offering.java. Schedule.java. Report.java. TestSchedule.java. TestReport.java.


14. A Simple Game.

Development Episodes.


15. Catalog.

Introduction. Path 1: Catalog.itemsMatching(query). Path 2: Query.matchesIn(catalog). Path 3: Process(catalog.data, query.data). Conclusion.


16. Planning Game Simulator.

Part 1: Original Code. Part 2: Redistributing Features. Removing Duplication, Selection Troubles, and a Few Burrs. Part 3: Pushing the Code Further.


17. Where to Go from Here.

Books. Admonitions. Exercises to Try. Web Sites.

IV. APPENDIXES.


A: Answers to Selected Questions.

B: Java Refactoring Tools.

C: Inverses for Refactorings.

D: Key Refactorings.

Bibliography.

Index.

Preface

Preface

What Is Refactoring?

Refactoring is the art of improving the design of existing code. Refactoring provides us with ways to recognize problematic code and gives us recipes for improving it.

What Are the Goals of This Book?

This book is a workbook designed to help you

  • Practice recognizing the most important smells (i.e., problems)
  • Apply the most important refactoring techniques
  • Think more about how to create great code
  • Have fun!

To a smaller extent, this book is a reference book with

  • A smell finder inside the covers
  • A standard format for describing smells
  • An appendix listing Java tools supporting refactoring
  • An appendix showing key refactorings

Who Is This Book For?

Refactoring being a technique for code, this book then is especially intended for practicing programmers who write and maintain code.

Students can also benefit from refactoring, although I'd expect they'd see the value only after they've had a chance to develop medium-sized or larger programs or had to work in teams (this probably applies to juniors, seniors, and graduate students).

What Background Do You Need?

It would be helpful to have the book, Refactoring: Improving the Design of Existing Code, by Martin Fowler et al. for its catalog of refactorings. (You can read my book and Refactoring at the same time.) Martin and his colleagues have worked out step-by-step instructions for many refactorings, and I will not repeat those in this book. Furthermore, they've provided a fully worked-out example, along with a lot of good discussion and background material. Someone determined to get through this book without that one could probably do it, but I wouldn't recommend it.

The examples in this book are written in Java. This is not because it's the easiest language to refactor, but because it's popular, and the best Java development environments provide automated refactoring support. A C# or C++ programmer has enough reading knowledge of Java to make sense of most of the questions. However, in later parts of the book, you will modify, test, and run larger programs, and this could be problematic for programmers using languages other than Java.

The book Design Patterns, by Gamma et al., describes patterns as "targets for refactoring." It would be helpful to have some familiarity with the ideas in that book because I freely refer to the patterns it mentions. If you're not yet familiar with Design Patterns, let me recommend Steve Metsker's book, Design Patterns Java Workbook, as well.

How to Use This Book

Solving a problem is more challenging than recognizing a solution. There are answers to some problems in the back of the book, but you'll learn more if you try the problems before peeking at the answers. If you work through the problems, you'll probably even find that you disagree with me on some answers. That will be more fun for all of us than if you just look at my answers and nod.

I think it's more fun to work with others (either a partner or in a small group), but I recognize that isn't always possible.

The later (longer) examples need to be done at a computer. Looking for problems, and figuring out how to solve them, is different when you're looking at a program in your environment.

Customer Reviews

Most Helpful Customer Reviews

See All Customer Reviews

Refactoring Workbook 5 out of 5 based on 0 ratings. 2 reviews.
Anonymous More than 1 year ago
Guest More than 1 year ago
Most books about programming teach us about a specific technology or two. Right now I¿m staring at some great books on my shelf that have taught me things like user interface programming in Java, templates in C++, how to work with XML files, and so on. Bill Wake¿s ¿Refactoring Workbook¿ goes well beyond books like these. Those books give me some fleeting insights into a technology du juor. Wake¿s book teaching me things that will stay with me throughout my career. I finished it having learned new skills that will make me a better programmer, regardless of what I¿m working on¿Java user interfaces, C++, or code to read XML files. The book includes over 100 exercises, many of which are answered in an appendix. I worked through the book alone but this is the type of book I¿d love to work through with a group.