Refactoring
Improving the Design of Existing Code
Martin Fowler
With contributions by Kent Beck,
John Brant, William Opdyke, and
Don Roberts
An imprint of Addison Wesley Longman, Inc.
Reading, Massachusetts Harlow, England Menlo Park, California
Berkeley, California Don Mills, Ontario Sydney
Bonn Amsterdam Tokyo Mexico City
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and Addison Wesley Longman, Inc., was aware of a trademark claim, the designations have been printed in initial capital letters or in all capital letters.
The authors and publisher have taken care in preparation of this book, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for incidental or consequential damages in connection with or arising out of the use of the information or programs contained herein.
For more information about buying this title in bulk quantities, or for special sales opportunities (which may include electronic versions; custom cover designs; and content particular to your business, training goals, marketing focus, or branding interests), please contact our corporate sales department at or (800) 382-3419.
For government sales inquiries, please contact .
For questions about sales outside the U.S., please contact .
Library of Congress Cataloging-in-Publication Data
Fowler, Martin,
Refactoring : improving the design of existing code / Martin
Fowler.
p. m. (The Addison-Wesley object technology series)
Includes bibliographical references and index.
ISBN 0-201-48567-2
1. Software refactoring. 2. Object-oriented programming (Computer
science) I. Title. II. Series.
QA76.76.R42F69 1999
005.14dc21 9920765
CIP
Copyright 1999 by Addison Wesley Longman, Inc.
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior written consent of the publisher. Printed in the United States of America. Published simultaneously in Canada.
Executive Editor: J. Carter Shanklin
Project Editor: Krysia Bebick
Editorial Assistant: Kristin Erickson
Production Manager: John Fuller
Production Coordinator: Genevieve C. Rajewski
Copy Editor: Catherine Judge Allen
Composition: Kim Arney
Index: Irv Hershman
Proofreader: Amy Finch
ISBN 0-201-48567-2
Text printed in the United States on recycled paper at Courier in Westford, Massachusetts.
Twenty-ninth printing, November 2014
The Addison-Wesley Object Technology Series
Grady Booch, Ivar Jacobson, and James Rumbaugh, Series Editors
For more information, check out the series web site at www.awprofessional.com/otseries.
Ahmed/Umrysh, Developing Enterprise Java Applications with J2EE and UML
Arlow/Neustadt, Enterprise Patterns and MDA: Building Better Software with Archetype Patterns and UML
Arlow/Neustadt, UML 2 and the Unified Process, Second Edition
Armour/Miller, Advanced Use Case Modeling: Software Systems
Bellin/Simone, The CRC Card Book
Bergstrm/Rberg, Adopting the Rational Unified Process: Success with the RUP
Binder, Testing Object-Oriented Systems: Models, Patterns, and Tools
Bittner/Spence, Managing Iterative Software Development Projects
Bittner/Spence, Use Case Modeling
Booch, Object Solutions: Managing the Object-Oriented Project
Booch, Object-Oriented Analysis and Design with Applications, 3E
Booch/Bryan, Software Engineering with ADA, 3E
Booch/Rumbaugh/Jacobson, The Unified Modeling Language User Guide, Second Edition
Box et al., Effective COM: 50 Ways to Improve Your COM and MTS-based Applications
Buckley/Pulsipher, The Art of ClearCase Deployment
Carlson, Modeling XML Applications with UML: Practical e-Business Applications
Clarke/Baniassad, Aspect-Oriented Analysis and Design
Collins, Designing Object-Oriented User Interfaces
Conallen, Building Web Applications with UML, 2E
DSouza/Wills, Objects, Components, and Frameworks with UML: The Catalysis(SM) Approach
Denney, Succeeding with Use Cases
Douglass, Doing Hard Time: Developing Real-Time Systems with UML, Objects, Frameworks, and Patterns
Douglass, Real-Time Design Patterns: Robust Scalable Architecture for Real-Time Systems
Douglass, Real Time UML, 3E: Advances in The UML for Real-Time Systems
Eeles et al., Building J2EEApplications with the Rational Unified Process
Fowler, Analysis Patterns: Reusable Object Models
Fowler, UML Distilled, 3E: A Brief Guide to the Standard Object Modeling Language
Fowler et al., Refactoring: Improving the Design of Existing Code
Gomaa, Designing Concurrent, Distributed, and Real-Time Applications with UML
Gomaa, Designing Software Product Lines with UML
Heinckiens, Building Scalable Database Applications: Object-Oriented Design, Architectures, and Implementations
Hofmeister/Nord/Dilip, Applied Software Architecture
Jacobson/Booch/Rumbaugh, The Unified Software Development Process
Jacobson/Ng, Aspect-Oriented Software Development with Use Cases
Jordan, C++ Object Databases: Programming with the ODMG Standard
Kleppe/Warmer/Bast, MDA Explained: The Model Driven Architecture: Practice and Promise
Kroll/Kruchten, The Rational Unified Process Made Easy: A Practitioners Guide to the RUP
Kroll/MacIsaac, Agility and Discipline Made Easy: Practices from OpenUP and RUP
Kruchten, The Rational Unified Process, 3E: An Introduction
LaLonde, Discovering Smalltalk
Lau, The Art of Objects: Object-Oriented Design and Architecture
Leffingwell/Widrig, Managing Software Requirements, 2E: A Use Case Approach
Manassis, Practical Software Engineering: Analysis and Design for the .NET Platform
Marshall, Enterprise Modeling with UML: Designing Successful Software through Business Analysis
McGregor/Sykes, A Practical Guide to Testing Object-Oriented Software
Mellor/Balcer, Executable UML: A Foundation for Model-Driven Architecture
Mellor et al., MDA Distilled: Principles of Model-Driven Architecture
Naiburg/Maksimchuk, UML for Database Design
Oestereich, Developing Software with UML, 2E: Object-Oriented Analysis and Design in Practice
Page-Jones, Fundamentals of Object-Oriented Design in UML
Pohl, Object-Oriented Programming Using C++, 2E
Quatrani, Visual Modeling with Rational Rose 2002 and UML
Rector/Sells, ATL Internals
Reed, Developing Applications with Visual Basic and UML
Rosenberg/Scott, Applying Use Case Driven Object Modeling with UML: An Annotated e-Commerce Example
Rosenberg/Scott, Use Case Driven Object Modeling with UML: A Practical Approach
Royce, Software Project Management: A Unified Framework
Rumbaugh/Jacobson/Booch, The Unified Modeling Language Reference Manual