Refactoring to Patterns (Addison-Wesley Signature Series) and over one million other books are available for Amazon Kindle. Learn more
CDN$ 44.72
  • List Price: CDN$ 70.99
  • You Save: CDN$ 26.27 (37%)
Only 3 left in stock (more on the way).
Ships from and sold by
Gift-wrap available.
Have one to sell?
Flip to back Flip to front
Listen Playing... Paused   You're listening to a sample of the Audible audio edition.
Learn more
See all 2 images

Refactoring to Patterns Hardcover – Aug 5 2004

See all 2 formats and editions Hide other formats and editions
Amazon Price New from Used from
Kindle Edition
"Please retry"
"Please retry"
CDN$ 44.72
CDN$ 41.00 CDN$ 28.95

2014 Books Gift Guide for Children & Teens
Browse our featured books to find gift ideas for the boys or girls on your holiday shopping list this year!

Frequently Bought Together

Refactoring to Patterns + Refactoring: Improving the Design of Existing Code + Working Effectively with Legacy Code
Price For All Three: CDN$ 130.38

Customers Who Bought This Item Also Bought

Product Details

  • Hardcover: 400 pages
  • Publisher: Addison-Wesley Professional; 1 edition (Aug. 5 2004)
  • Language: English
  • ISBN-10: 0321213351
  • ISBN-13: 978-0321213358
  • Product Dimensions: 17.8 x 2.5 x 23.6 cm
  • Shipping Weight: 980 g
  • Average Customer Review: 5.0 out of 5 stars  See all reviews (1 customer review)
  • Amazon Bestsellers Rank: #232,531 in Books (See Top 100 in Books)
  • See Complete Table of Contents

Product Description

From the Inside Flap

What Is This Book About?

This book is about the marriage of refactoring—the process of improving the design of existing code—with patterns, the classic solutions to recurring design problems. Refactoring to Patterns suggests that using patterns to improve an existing design is better than using patterns early in a new design. This is true whether code is years old or minutes old. We improve designs with patterns by applying sequences of low-level design transformations, known as refactorings.

What Are the Goals of This Book?

This book was written to help you:

  • Understand how to combine refactoring and patterns
  • Improve the design of existing code with pattern-directed refactorings
  • Identify areas of code in need of pattern-directed refactorings
  • Learn why using patterns to improve existing code is better than using patterns early in a new design

To achieve these goals, this book includes the following features:

  • A catalog of 27 refactorings
  • Examples based on real-world code, not the toy stuff
  • Pattern descriptions, including real-world pattern examples
  • A collection of smells (i.e., problems) that indicate the need for pattern-directed refactorings
  • Examples of different ways to implement the same pattern
  • Advice for when to refactor to, towards, or away from patterns

To help individuals or groups learn the 27 refactorings in the book, you’ll find a suggested study sequence on the inside back cover of the book.

Who Should Read This Book?

This book is for object-oriented programmers engaged in or interested in improving the design of existing code. Many of these programmers use patterns and/or practice refactoring but have never implemented patterns by refactoring; others know little about refactoring and patterns and would like to learn more.

This book is useful for both greenfield development, in which you are writing a new system or feature from scratch, and legacy development, in which you are mostly maintaining a legacy system.

What Background Do You Need?

This book assumes you are familiar with design concepts like tight coupling and loose coupling as well as object-oriented concepts like inheritance, polymorphism, encapsulation, composition, interfaces, abstract and concrete classes, abstract and static methods, and so forth.

I use Java examples in this book. I find that Java tends to be easy for most object-oriented programmers to read. I’ve gone out of my way to not use fancy Java features, so whether you code in C++, C#, Visual Basic .NET, Python, Ruby, Smalltalk, or some other object-oriented language, you ought to be able to understand the Java code in this book.

This book is closely tied to Martin Fowler’s classic book Refactoring F. It contains references to low-level refactorings, such as:

  • Extract Method
  • Extract Interface
  • Extract Superclass
  • Extract Subclass
  • Pull Up Method
  • Move Method
  • Rename Method

Refactoring also contains references to more sophisticated refactorings, such as:

  • Replace Inheritance with Delegation
  • Replace Conditional with Polymorphism
  • Replace Type Code with Subclasses

To understand the pattern-directed refactorings in this book, you don’t need to know every refactoring listed above. Instead, you can follow the example code that illustrates how the listed refactorings are implemented. However, if you want to get the most out of this book, I do recommend that you have Refactoring close by your side. It’s an invaluable refactoring resource, as well as a useful aid for understanding this book.

The patterns I write about come from the classic book Design Patterns DP, as well as from authors such as Kent Beck, Bobby Woolf, and myself. These are patterns that my colleagues and I have refactored to, towards, or away from on real-world projects. By learning the art of pattern-directed refactorings, you’ll understand how to refactor to, towards, or away from patterns not mentioned in this book.

You don’t need expert knowledge of these patterns to read this book, though some knowledge of patterns is useful. To help you understand the patterns I’ve written about, this book includes brief pattern summaries, UML sketches of patterns, and many example implementations of patterns. To get a more detailed understanding of the patterns, I recommend that you study this book in conjunction with the patterns literature I reference.

This book uses UML 2.0 diagrams. If you don’t know UML very well, you’re in good company. I know the basics. While writing this book, I kept the third edition of Fowler’s UML Distilled Fowler, UD close by my side and referred to it often.

How to Use This Book

To get a high-level understanding of the refactorings in this book, you can begin by studying each refactoring’s summary (see Format of the Refactorings, 47), as well as its Benefits and Liabilities box, which appears at the end of each refactoring’s Motivation section.

To get a deeper understanding of the refactorings, you’ll want to study every part of a refactoring, with the exception of the Mechanics section. The Mechanics section is special. It’s intended to help you implement a refactoring by suggesting what low-level refactorings to follow. To understand a refactoring in this book, you don’t have to read the Mechanics section. You’re more likely to use the Mechanics section as a reference when you’re actually refactoring.

The coding smells described in this book and in Refactoring F provide a useful way to identify a design problem and find associated refactorings to help fix the problem. You can also scan the alphabetized listing of refactorings (on the inside covers of this book and Refactoring ) to find a refactoring that can help improve a design.

This book documents the refactorings that take a design either to, towards, or away from a pattern. To help you figure out what direction to go in, you’ll find a section on this subject (called Refactoring to, towards, and away from Patterns, 29) as well as a table (listed on the inside front cover) that shows each pattern name and the refactorings you can apply to take a design to, towards, or away from the pattern.

The History of This Book

I began writing this book sometime in 1999. At the time, there were several forces driving me to write about patterns, refactoring, and extreme programming (XP) Beck, XP. First, I was surprised that patterns had not been mentioned in the XP literature. This led me to write a paper called “Patterns & XP” Kerievsky, PXP in which I publicly discussed the subject and offered some suggestions on how to integrate these two great contributions to our field.

Second, I knew that Martin Fowler had included only a few refactorings to patterns in Refactoring F, and he clearly stated that he hoped someone would write more. That seemed like a worthwhile goal.

Finally, I noticed that people in The Design Patterns Workshop, a class that my colleagues and I teach, needed more help in figuring out when to actually apply a pattern to a design. It’s one thing to learn what a pattern is and an altogether different thing to really understand when and how to apply the pattern. I thought that these students needed to study real-world examples of cases where applying a pattern to a design makes sense, and thus I began compiling a catalog of such examples.

As soon as I began writing this book, I followed Bruce Eckel’s lead and placed my rather rough contents on the Web to obtain feedback. The Web is indeed a beautiful thing. Many folks responded with suggestions, encouragement, and appreciation.

As my writings and ideas matured, I began presenting the subject of Refactoring to Patterns in conference tutorials and during Industrial Logic’s intensive patterns and refactoring workshops. This led to more suggestions for improvement and many ideas on what programmers needed to understand this subject.

Gradually I came to see that patterns are best viewed in the light of refactoring and that they are destinations best reached by applying sequences of lowlevel refactorings.

When my writings began to resemble a book, rather than a long paper, I was fortunate enough to have many experienced practitioners review my work and offer suggestions for improvement. You can read more about these folks in the Acknowledgments section.

Standing on the Shoulders of Giants

In the summer of 1995, I walked into a bookstore, encountered the book Design Patterns DP for the first time, and fell in love with patterns. I wish to thank the authors, Erich Gamma, Richard Helm (whom I still haven’t met), Ralph Johnson, and John Vlissides for writing such an excellent piece of literature. The wisdom you shared in your book has helped me become a much better software designer.

Somewhere around 1996, before he became famous, I met Martin Fowler at a patterns conference. It was to be the beginning of a long friendship. I doubt whether I would have written this book if Martin (and his colleagues, Kent Beck, William Opdyke, John Brant, and Don Roberts) had not written the classic book Refactoring F. Like Design Patterns, Refactoring utterly changed the way I approach software design.

My writings in this book could only have happened because of the hard work of the authors of Design Patterns and Refactoring. I can’t thank you all enough for your great books.

From the Back Cover

In 1994,Design Patternschanged the landscape of object-oriented development by introducing classic solutions to recurring design problems. In 1999,Refactoringrevolutionized design by introducing an effective process for improving code. With the highly anticipatedRefactoring to Patterns, Joshua Kerievsky has changed our approach to design by forever uniting patterns with the evolutionary process of refactoring.

This book introduces the theory and practice of pattern-directed refactorings: sequences of low-level refactorings that allow designers to safely move designs to, towards, or away from pattern implementations. Using code from real-world projects, Kerievsky documents the thinking and steps underlying over two dozen pattern-based design transformations. Along the way he offers insights into pattern differences and how to implement patterns in the simplest possible ways.

Coverage includes:

  • A catalog of twenty-seven pattern-directed refactorings, featuring real-world code examples
  • Descriptions of twelve design smells that indicate the need for this book’s refactorings
  • General information and new insights about patterns and refactoring
  • Detailed implementation mechanics: how low-level refactorings are combined to implement high-level patterns
  • Multiple ways to implement the same pattern—and when to use each
  • Practical ways to get started even if you have little experience with patterns or refactoring

Refactoring to Patternsreflects three years of refinement and the insights of more than sixty software engineering thought leaders in the global patterns, refactoring, and agile development communities. Whether you’re focused on legacy or “greenfield” development, this book will make you a better software designer by helping you learn how to make important design changes safely and effectively.

What Other Items Do Customers Buy After Viewing This Item?

Customer Reviews

5.0 out of 5 stars
5 star
4 star
3 star
2 star
1 star
See the customer review
Share your thoughts with other customers

Most helpful customer reviews

6 of 6 people found the following review helpful By Nicholas Roeder on June 25 2005
Format: Hardcover
This is probably the best technical book I read that was published in 2004. If you are struggling to see how you can apply patterns in your day-to-day work, this book will help.
Most development work is done with existing code bases. It is less likely that you will have a chance to design something from scratch using design patterns that you are aware of. So this book helps you move toward a code base that is better designed in refactorings that lead to common design patterns.
The author suggests that many systems are now "over-engineered" due to the popularity of design patterns. I have not had the opportunity to work on such a system, but the book was still very relevant.
The code examples are actually very realistic and detailed, which I appreciated. Some readers may find them too complex and distracting from the refactoring steps, but I thought they strengthened the book.
I read the book in the order suggested by the author to those who want to study the patterns. It worked very well and the code examples carried thoughtfully from one refactoring to the next.
Examples are in Java but if you are using any OO language you will likely be able to follow them.
Many technical books are filled with typos and grammatical errors. This book was obviously well edited and not rushed out the door to publish.
Was this review helpful to you? Yes No Sending feedback...
Thank you for your feedback. If this review is inappropriate, please let us know.
Sorry, we failed to record your vote. Please try again.

Most Helpful Customer Reviews on (beta) 56 reviews
77 of 81 people found the following review helpful
A book I've been waiting for Sept. 5 2004
By wiredweird - Published on
Format: Hardcover Verified Purchase
Kerievsky has done it. He has started to pull together anti-patterns (a.k.a. "bad smells"), refactorings, and patterns into one unified study. All three work well individually. Together, they make a powerful combination.

This isn't as rigorously analytic as the original Design Patterns book. I fully expect more theory-oriented writers to follow the trail blazed here. Instead, Kerievsky gives worked examples, in great detail. At every point, he starts with a code sample drawn from real life, complex enough to be interesting. Then, step by step, he shows the incremental changes made to transition from it's problematic start to its pattern-based end point. Experienced programmers may find this plodding and repetitive. Beginners, however, often have a hard time planning incremental changes and executing them. The author takes care to keep the code in working order at each increment, showing a clear path through the forest of possibilities. Some readers may even trace the path backwards, giving another look at how each change moves toward the end state. The worked examples are the real strength of this text.

This is a book for the software maintainer. In other words, it addresses 90% or 99% of the work that real programmers do. Just about every other software text on the market assumes that the project just started - the disks are empty and the compiler shrink-wrap is on the floor. I admit, that kind of programming is the most fun. It's just not realistic, though. Most work is rework, the kind demonstrated here.

Another great feature of this book is what it lacks: dogmatic harangues about methodology. It even keeps a skeptical attitude towards patterns, since heavyweight design techniques aren't always right for lightweight problems. Kerievsky mentions agile-ism, but doesn't make it a part of the process. He does, however, take the continuous testing idea from the eXtremists and work that into the demonstrations. Bravo! Hardware designers may wonder what the fuss is about, since thorough testing has been part of their culture for years. It's a happy novelty in much of the software world, though, and deserves to become standard practice.

My only problem with this book is that there isn't more of it. For example, constructor chaining is a great idea. There are two kind of chain, though. He shows the increasing parameter list, where simpler constructors supply default values for the more ones with more parameters. It's also possible to chain in decreasing order, where each constructor processes one parameter and passes on the simplified list. (What's good for constructors, of course, is also good for other collections of related methods.)

The book's ideal reader understands an OO language, uses subclassing regularly, and knows something about design patterns. That reader, with enough patience to follow the examples, will learn a lot. More experienced developers won't need the step by step approach, but may benefit from seeing multiple refactorings working together to solve a complex problem. It has my highest recommendation for any developer who really thinks about design and redesign.

46 of 49 people found the following review helpful
Wonderful! Brings patterns into coding, not just designing Sept. 19 2004
By Michael Cohn - Published on
Format: Hardcover
Based on its title alone I had high expectations for this book. It didn't disappoint. The book takes two of the most important advances of the past decade (patterns and refactoring) and puts them together into a whole that is definitely more than the sum of its parts.

I've read many good patterns books and have been applying patterns to how I think and talk about software since the original "Design Patterns" book in 1995. However, something was always missing. Through my consulting work, whenever I introduced patterns to a new team they would take quickly to the idea and patterns would become part of how they thought-but only when designing, not when coding. Since we spent more time coding than designing, patterns played less of a role than they could have.

This book does an excellent job of bringing patterns into coding, rather than relegating them just to design discussions. As the author points out, "patterns are best viewed in the light of refactoring and that they are destinations best reached by applying sequences of low-level refactorings."

This book has earned a permanent place on my bookshelf. That is, when it's not open beside me as I program. Very highly recommended!
58 of 65 people found the following review helpful
Over-complicated examples ruin a superb piece of work. Nov. 7 2004
By Cybergeek - Published on
Format: Hardcover
This book is the only one of its kind that tries to use a patterns approach to refactoring. It is a good add-on to Martin Fowler's book. It's a very valuable contribution to the refactoring community. Kerievsky has a no-nonsense, down-to-earth approach to the subject of Patterns. However unlike Fowler who makes an effort to keep the code examples in his book as simple as possible, Kerievsky has made his examples over-complicated with all kinds of detailed finance domain references and the XML DOM. The example he uses to show how the Builder pattern simplifies creation of Composites is like a really heavy chapter on XML processing/generation.

The "Replace Conditional Logic with Strategy" is like a chapter on Investments / Loans. It really distracts the reader's attention from the pattern or refactoring.

This is a shame because it is impossible to write a good book on refactoring without nice examples. It is also a bit surprising that none of the other Amazon reviews mention this issue.
19 of 20 people found the following review helpful
A remarkable work, with genuine wisdom and solid pragmatism Aug. 24 2004
By John Tangney - Published on
Format: Hardcover
This book goes much further than Martin Fowler's seminal work on refactoring. Indeed, it goes further than the GoF's canonical work on patterns. By combining the two, Kerievsky breaks new ground.

The refactorings are accessible and beautifully presented. As with the GoF book, a lot of the rationale will ring a bell. "Gee, I've seen this before..." The value of these refactorings lie precisely in that corner, where the mechanics of refactoring with a GoF pattern as the goal allow one to improve the readability and maintainability of the code.

Some of the refactorings were less than obvious to me until I read this book. And that's where Kerievsky's mastery shows. He presents fresh ideas (to me, anyway) with solid examples, and thoroughly thought-out steps.

The examples deserve special mention. How many times have you read a "manual" or other technical how-to with toy examples that fail to illustrate the point? Or with examples so narrow that they hardly approach your real-world situation. (I could name names... ;->) OTOH, how many examples are so long and laborious, that gleaning any useful information requires learning the author's example-problem domain before you can get anywhere?

Kerievsky walks the tightrope between toy examples and over-engineered examples with tremendous skill. They're Goldilocks examples: Neither too big, nor too small, his examples are juuust right.

Another area in which some tightrope walking is required is presenting material that's suitable for a tutorial, vs. material that makes for easy access as a reference. Josh somehow manages to balance the two. Reading from begining to end, one is able to appreciate the tutorial nature of the material. However, (like Fowler's Refactoring) easy look-up is made possible by the formal presentation of each refactoring.

I heartily recommend this book to anyone who cares about Software Craftsmanship (my plug for Pete McBreen's book too!)

Disclaimer: This review is based on a prepublication manuscript.
14 of 14 people found the following review helpful
Could have been a 5! Oct. 5 2005
By Dennis Becton - Published on
Format: Hardcover
The book is great, and I've learned a lot from it. I REALLY wanted to give it 5 stars, but the lack of full source code for the examples, detailing before and after application of the refactoring techniques, forced me to give it a 3. Ended up spending way too much time trying to piece together the snippets of code in order to fully understand what was going on.