Home > Store

Refactoring: Improving the Design of Existing Code, 2nd Edition

Register your product to gain access to bonus material or receive a coupon.

Refactoring: Improving the Design of Existing Code, 2nd Edition

Best Value Purchase

Book + eBook + Web Edition Bundle

  • Your Price: $64.79
  • List Price: $107.98
  • Includes EPUB, MOBI, and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    MOBI MOBI The eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

  • About this Web Edition
  • A Web Edition is an online learning product that you view in your web browser while connected to the Internet. Some Web Editions include additional interactive features, such as videos, quizzes, or live code editing. Read the product description for more details. A Web Edition will be accessible from your Account page after purchase.

    Viewing a Web Edition requires a web browser that fully supports HTML5. Supported platforms are:

    • Windows XP (Firefox only)
    • Windows 7, 8, or 10 (IE10, IE11, Chrome, or Firefox)
    • Mac OS X (Safari, Firefox, or Chrome)
    • Linux (Chrome or Firefox)
    • iOS 6, 7, or 8 (Mobile Safari)

More Purchase Options

Book + Web Edition

  • Your Price: $47.99
  • List Price: $59.99
  • About this Web Edition
  • A Web Edition is an online learning product that you view in your web browser while connected to the Internet. Some Web Editions include additional interactive features, such as videos, quizzes, or live code editing. Read the product description for more details. A Web Edition will be accessible from your Account page after purchase.

    Viewing a Web Edition requires a web browser that fully supports HTML5. Supported platforms are:

    • Windows XP (Firefox only)
    • Windows 7, 8, or 10 (IE10, IE11, Chrome, or Firefox)
    • Mac OS X (Safari, Firefox, or Chrome)
    • Linux (Chrome or Firefox)
    • iOS 6, 7, or 8 (Mobile Safari)

eBook (Watermarked) + Web Edition

  • Your Price: $38.39
  • List Price: $47.99
  • Includes EPUB, MOBI, and PDF
  • About eBook Formats
  • This eBook includes the following formats, accessible from your Account page after purchase:

    ePub EPUB The open industry format known for its reflowable content and usability on supported mobile devices.

    MOBI MOBI The eBook format compatible with the Amazon Kindle and Amazon Kindle applications.

    Adobe Reader PDF The popular standard, used most often with the free Adobe® Reader® software.

    This eBook requires no passwords or activation to read. We customize your eBook by discreetly watermarking it with your name, making it uniquely yours.

  • About this Web Edition
  • A Web Edition is an online learning product that you view in your web browser while connected to the Internet. Some Web Editions include additional interactive features, such as videos, quizzes, or live code editing. Read the product description for more details. A Web Edition will be accessible from your Account page after purchase.

    Viewing a Web Edition requires a web browser that fully supports HTML5. Supported platforms are:

    • Windows XP (Firefox only)
    • Windows 7, 8, or 10 (IE10, IE11, Chrome, or Firefox)
    • Mac OS X (Safari, Firefox, or Chrome)
    • Linux (Chrome or Firefox)
    • iOS 6, 7, or 8 (Mobile Safari)

Web Edition

  • Your Price: $38.39
  • List Price: $47.99
  • About this Web Edition
  • A Web Edition is an online learning product that you view in your web browser while connected to the Internet. Some Web Editions include additional interactive features, such as videos, quizzes, or live code editing. Read the product description for more details. A Web Edition will be accessible from your Account page after purchase.

    Viewing a Web Edition requires a web browser that fully supports HTML5. Supported platforms are:

    • Windows XP (Firefox only)
    • Windows 7, 8, or 10 (IE10, IE11, Chrome, or Firefox)
    • Mac OS X (Safari, Firefox, or Chrome)
    • Linux (Chrome or Firefox)
    • iOS 6, 7, or 8 (Mobile Safari)

About

Features

  • The first update to a classic that is the standard reference for refactoring in over 15 years
  • Enhanced, web-based features including interactive examples, video snippets, code highlighting
  • Extensive use of JavaScript examples

Description

  • Copyright 2019
  • Dimensions: 7-3/8" x 9-1/8"
  • Pages: 448
  • Edition: 2nd
  • Book
  • ISBN-10: 0-13-475759-9
  • ISBN-13: 978-0-13-475759-9

Fully Revised and Updated–Includes New Refactorings and Code Examples

“Any fool can write code that a computer can understand. Good programmers write code that humans can understand.”
—M. Fowler (1999)
For more than twenty years, experienced programmers worldwide have relied on Martin Fowler’s Refactoring to improve the design of existing code and to enhance software maintainability, as well as to make existing code easier to understand.


This eagerly awaited new edition has been fully updated to reflect crucial changes in the programming landscape. Refactoring, Second Edition, features an updated catalog of refactorings and includes JavaScript code examples, as well as new functional examples that demonstrate refactoring without classes.


Like the original, this edition explains what refactoring is; why you should refactor; how to recognize code that needs refactoring; and how to actually do it successfully, no matter what language you use.

  • Understand the process and general principles of refactoring
  • Quickly apply useful refactorings to make a program easier to comprehend and change
  • Recognize “bad smells” in code that signal opportunities to refactor
  • Explore the refactorings, each with explanations, motivation, mechanics, and simple examples
  • Build solid tests for your refactorings
  • Recognize tradeoffs and obstacles to refactoring

Includes free access to the canonical web edition, with even more refactoring resources. (See inside the book for details about how to access the web edition.)

Extras

Author's Site

Please visit the author's site at martinfowler.com.

Sample Content

Table of Contents

Foreword to the First Edition xi

Preface xiii

Chapter 1: Refactoring: A First Example 1

The Starting Point 1

Comments on the Starting Program 3

The First Step in Refactoring 5

Decomposing the statement Function 6

Status: Lots of Nested Functions 22

Splitting the Phases of Calculation and Formatting 24

Status: Separated into Two Files (and Phases) 31

Reorganizing the Calculations by Type 34

Status: Creating the Data with the Polymorphic Calculator 41

Final Thoughts 43

Chapter 2: Principles in Refactoring 45

Defining Refactoring 45

The Two Hats 46

Why Should We Refactor? 47

When Should We Refactor? 50

Problems with Refactoring 55

Refactoring, Architecture, and Yagni 62

Refactoring and the Wider Software Development Process 63

Refactoring and Performance 64

Where Did Refactoring Come From? 67

Automated Refactorings 68

Going Further 70

Chapter 3: Bad Smells in Code 71

Mysterious Name 72

Duplicated Code 72

Long Function 73

Long Parameter List 74

Global Data 74

Mutable Data 75

Divergent Change 76

Shotgun Surgery 76

Feature Envy 77

Data Clumps 78

Primitive Obsession 78

Repeated Switches 79

Loops 79

Lazy Element 80

Speculative Generality 80

Temporary Field 80

Message Chains 81

Middle Man 81

Insider Trading 82

Large Class 82

Alternative Classes with Different Interfaces 83

Data Class 83

Refused Bequest 83

Comments 84

Chapter 4: Building Tests 85

The Value of Self-Testing Code 85

Sample Code to Test 87

A First Test 90

Add Another Test 93

Modifying the Fixture 95

Probing the Boundaries 96

Much More Than This 99

Chapter 5: Introducing the Catalog 101

Format of the Refactorings 101

The Choice of Refactorings 102

Chapter 6: A First Set of Refactorings 105

Extract Function 106

Inline Function 115

Extract Variable 119

Inline Variable 123

Change Function Declaration 124

Encapsulate Variable 132

Rename Variable 137

Introduce Parameter Object 140

Combine Functions into Class 144

Combine Functions into Transform 149

Split Phase 154

Chapter 7: Encapsulation 161

Encapsulate Record 162

Encapsulate Collection 170

Replace Primitive with Object 174

Replace Temp with Query 178

Extract Class 182

Inline Class 186

Hide Delegate 189

Remove Middle Man 192

Substitute Algorithm 195

Chapter 8: Moving Features 197

Move Function 198

Move Field 207

Move Statements into Function 213

Move Statements to Callers 217

Replace Inline Code with Function Call 222

Slide Statements 223

Split Loop 227

Replace Loop with Pipeline 231

Remove Dead Code 237

Chapter 9: Organizing Data 239

Split Variable 240

Rename Field 244

Replace Derived Variable with Query 248

Change Reference to Value 252

Change Value to Reference 256

Chapter 10: Simplifying Conditional Logic 259

Decompose Conditional 260

Consolidate Conditional Expression 263

Replace Nested Conditional with Guard Clauses 266

Replace Conditional with Polymorphism 272

Introduce Special Case 289

Introduce Assertion 302

Chapter 11: Refactoring APIs 305

Separate Query from Modifier 306

Parameterize Function 310

Remove Flag Argument 314

Preserve Whole Object 319

Replace Parameter with Query 324

Replace Query with Parameter 327

Remove Setting Method 331

Replace Constructor with Factory Function 334

Replace Function with Command 337

Replace Command with Function 344

Chapter 12: Dealing with Inheritance 349

Pull Up Method 350

Pull Up Field 353

Pull Up Constructor Body 355

Push Down Method 359

Push Down Field 361

Replace Type Code with Subclasses 362

Remove Subclass 369

Extract Superclass 375

Collapse Hierarchy 380

Replace Subclass with Delegate 381

Replace Superclass with Delegate 399

Bibliography 405

Index 409

Updates

Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership