logo资料库

Refactoring to patterns - Joshua Kerievsky.pdf

第1页 / 共531页
第2页 / 共531页
第3页 / 共531页
第4页 / 共531页
第5页 / 共531页
第6页 / 共531页
第7页 / 共531页
第8页 / 共531页
资料共531页,剩余部分请下载后查看
Chapter 1. Why I Wrote This Book
Over-Engineering
The Patterns Panacea
Under-Engineering
Test-Driven Development and Continuous Refactoring
Refactoring and Patterns
Evolutionary Design
Chapter 2. Refactoring
What Is Refactoring?
What Motivates Us to Refactor?
Many Eyes
Human-Readable Code
Keeping It Clean
Small Steps
Design Debt
Evolving a New Architecture
Composite and Test-Driven Refactorings
The Benefits of Composite Refactorings
Refactoring Tools
Chapter 3. Patterns
What Is a Pattern?
Patterns Happy
There Are Many Ways to Implement a Pattern
Refactoring to, towards, and away from Patterns
Table 3.1.
Do Patterns Make Code More Complex?
Pattern Knowledge
Up-Front Design with Patterns
Chapter 4. Code Smells
Table 4.1.
Duplicated Code
Long Method
Conditional Complexity
Primitive Obsession
Indecent Exposure
Solution Sprawl
Alternative Classes with Different Interfaces
Lazy Class
Large Class
Switch Statements
Combinatorial Explosion
Oddball Solution
Chapter 5. A Catalog of Refactorings to Patterns
Format of the Refactorings
Benefits and Liabilities
Projects Referenced in This Catalog
XML Builders
HTML Parser
Loan Risk Calculator
A Starting Point
A Study Sequence
Table 5.1.
Chapter 6. Creation
Replace Constructors with Creation Methods
Motivation
Creation Methods and Factory Methods
Benefits and Liabilities
Mechanics
Example
Variations
Parameterized Creation Methods
Extract Factory
Move Creation Knowledge to Factory
Motivation
What Is a Factory?
Benefits and Liabilities
Mechanics
Example
Encapsulate Classes with Factory
Motivation
Benefits and Liabilities
Mechanics
Example
Variations
Encapsulating Inner Classes
Introduce Polymorphic Creation with Factory Method
Motivation
Benefits and Liabilities
Mechanics
Example
Encapsulate Composite with Builder
Benefits and Liabilities
Mechanics
Example
Improving a Builder
Variations
A Schema-Based Builder
Inline Singleton
Motivation
Ward Cunningham on Singletons
Kent Beck on Singletons
Benefits and Liabilities
Mechanics
Example
Chapter 7. Simplification
Compose Method
Motivation
Benefits and Liabilities
Mechanics
Example
Replace Conditional Logic with Strategy
Motivation
Benefits and Liabilities
Mechanics
Example
Move Embellishment to Decorator
Motivation
Decorator versus Strategy
Benefits and Liabilities
Mechanics
Example
Replace State-Altering Conditionals with State
Motivation
Benefits and Liabilities
Mechanics
Example
Replace Implicit Tree with Composite
Motivation
Benefits and Liabilities
Mechanics
Example
Replace Conditional Dispatcher with Command
Motivation
Benefits and Liabilities
Mechanics
Example
Chapter 8. Generalization
Form Template Method
Motivation
Benefits and Liabilities
Mechanics
Example
Extract Composite
Motivation
Benefits and Liabilities
Mechanics
Example
Replace One/Many Distinctions with Composite
Motivation
Benefits and Liabilities
Mechanics
Example
Replace Hard-Coded Notifications with Observer
Motivation
Benefits and Liabilities
Mechanics
Example
Unify Interfaces with Adapter
Motivation
Benefits and Liabilities
Mechanics
Example
Extract Adapter
Motivation
Adapter and Facade
Benefits and Liabilities
Mechanics
Example
Variations
Adapting with Anonymous Inner Classes
Replace Implicit Language with Interpreter
Motivation
Benefits and Liabilities
Mechanics
Example
Chapter 9. Protection
Replace Type Code with Class
Motivation
Benefits and Liabilities
Mechanics
Example
Limit Instantiation with Singleton
Motivation
Benefits and Liabilities
Mechanics
Example
Introduce Null Object
Motivation
Benefits and Liabilities
Mechanics
Example
Background for the Example: Mouse Events in Java 1.0
Chapter 10. Accumulation
Move Accumulation to Collecting Parameter
Motivation
Benefits and Liabilities
Mechanics
Example
Move Accumulation to Visitor
Motivation
Benefits and Liabilities
Mechanics
External Accumulation Method
Internal Accumulation Method
Visitor Replacement
Example
Chapter 11. Utilities
Chain Constructors
Motivation
Mechanics
Example
Unify Interfaces
Motivation
Mechanics
Example
Extract Parameter
Motivation
Mechanics
Example
Afterword
References
Inside Front Cover
List of Refactorings
Refactoring Directions
Inside Back Cover
Code Smells
A Study Sequence
Chapter Menu What Is This Book About? What Are the Goals of This Book? Who Should Read This Book? What Background Do You Need? How to Use This Book The History of This Book Standing on the Shoulders of Giants Acknowledgments Chapter 1. Why I Wrote This Book Over-Engineering The Patterns Panacea Under-Engineering Test-Driven Development and Continuous Refactoring Refactoring and Patterns Evolutionary Design Chapter 2. Refactoring What Is Refactoring? What Motivates Us to Refactor? Many Eyes Human-Readable Code Keeping It Clean Small Steps Design Debt Evolving a New Architecture Composite and Test-Driven Refactorings The Benefits of Composite Refactorings Refactoring Tools Chapter 3. Patterns What Is a Pattern? Patterns Happy There Are Many Ways to Implement a Pattern Refactoring to, towards, and away from Patterns Table 3.1. Do Patterns Make Code More Complex? Pattern Knowledge Up-Front Design with Patterns Chapter 4. Code Smells Table 4.1.
Duplicated Code Long Method Conditional Complexity Primitive Obsession Indecent Exposure Solution Sprawl Alternative Classes with Different Interfaces Lazy Class Large Class Switch Statements Combinatorial Explosion Oddball Solution Chapter 5. A Catalog of Refactorings to Patterns Format of the Refactorings Benefits and Liabilities Projects Referenced in This Catalog XML Builders HTML Parser Loan Risk Calculator A Starting Point A Study Sequence Table 5.1. Chapter 6. Creation Replace Constructors with Creation Methods Motivation Creation Methods and Factory Methods Benefits and Liabilities Mechanics Example Variations Parameterized Creation Methods Extract Factory Move Creation Knowledge to Factory Motivation What Is a Factory? Benefits and Liabilities Mechanics Example Encapsulate Classes with Factory Motivation Benefits and Liabilities Mechanics Example Variations Encapsulating Inner Classes
Introduce Polymorphic Creation with Factory Method Motivation Benefits and Liabilities Mechanics Example Encapsulate Composite with Builder Benefits and Liabilities Mechanics Example Improving a Builder Variations A Schema-Based Builder Inline Singleton Motivation Ward Cunningham on Singletons Kent Beck on Singletons Benefits and Liabilities Mechanics Example Chapter 7. Simplification Compose Method Motivation Benefits and Liabilities Mechanics Example Replace Conditional Logic with Strategy Motivation Benefits and Liabilities Mechanics Example Move Embellishment to Decorator Motivation Decorator versus Strategy Benefits and Liabilities Mechanics Example Replace State-Altering Conditionals with State Motivation Benefits and Liabilities Mechanics Example Replace Implicit Tree with Composite Motivation Benefits and Liabilities Mechanics Example
Replace Conditional Dispatcher with Command Motivation Benefits and Liabilities Mechanics Example Chapter 8. Generalization Form Template Method Motivation Benefits and Liabilities Mechanics Example Extract Composite Motivation Benefits and Liabilities Mechanics Example Replace One/Many Distinctions with Composite Motivation Benefits and Liabilities Mechanics Example Replace Hard-Coded Notifications with Observer Motivation Benefits and Liabilities Mechanics Example Unify Interfaces with Adapter Motivation Benefits and Liabilities Mechanics Example Extract Adapter Motivation Adapter and Facade Benefits and Liabilities Mechanics Example Variations Adapting with Anonymous Inner Classes Replace Implicit Language with Interpreter Motivation Benefits and Liabilities Mechanics Example Chapter 9. Protection
Replace Type Code with Class Motivation Benefits and Liabilities Mechanics Example Limit Instantiation with Singleton Motivation Benefits and Liabilities Mechanics Example Introduce Null Object Motivation Benefits and Liabilities Mechanics Example Background for the Example: Mouse Events in Java 1.0 Chapter 10. Accumulation Move Accumulation to Collecting Parameter Motivation Benefits and Liabilities Mechanics Example Move Accumulation to Visitor Motivation Benefits and Liabilities Mechanics External Accumulation Method Internal Accumulation Method Visitor Replacement Example Chapter 11. Utilities Chain Constructors Motivation Mechanics Example Unify Interfaces Motivation Mechanics Example Extract Parameter Motivation Mechanics Example Afterword
References Inside Front Cover List of Refactorings Refactoring Directions Inside Back Cover Code Smells A Study Sequence
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.
分享到:
收藏