Refactoring Improving the Design of Existing Code
Сумата се прибавя директно в кошницата
6.41 €
.
Contents
Foreword xiii
Preface xv
What Is Refactoring? xvi
What’s in This Book? xvii
Who Should Read This Book? xviii
Building on the Foundations Laid by Others xix
Acknowledgments xix
Chapter 1: Refactoring, a First Example 1
The Starting Point 1
The First Step in Refactoring 7
Decomposing and Redistributing the Statement Method 8
Replacing the Conditional Logic on Price Code
with Polymorphism 34
Final Thoughts 52
Chapter 2: Principles in Refactoring 53
Defining Refactoring 53
Why Should You Refactor? 55
When Should You Refactor? 57
What Do I Tell My Manager? 60
Problems with Refactoring 62
Refactoring and Design 66
Refactoring and Performance 69
Where Did Refactoring Come From? 71
Chapter 3: Bad Smells in Code (by Kent Beck and Martin Fowler) . . 75
Duplicated Code 76
Long Method 76
Large Class 78
Long Parameter List 78
Divergent Change 79
Shotgun Surgery 80
Feature Envy 80
Data Clumps 81
Primitive Obsession 81
Switch Statements 82
Parallel Inheritance Hierarchies 83
Lazy Class 83
Speculative Generality 83
Temporary Field 84
Message Chains 84
Middle Man 85
Inappropriate Intimacy 85
Alternative Classes with Different Interfaces 85
Incomplete Library Class 86
Data Class 86
Refused Bequest 87
Comments 87
Chapter 4: Building Tests 89
The Value of Self-testing Code 89
The JUnit Testing Framework 91
Adding More Tests 97
Chapter 5: Toward a Catalog of Refactorings 103
Format of the Refactorings 103
Finding References 105
How Mature Are These Refactorings? 106
Chapter 6: Composing Methods 109
Extract Method 110
Inline Method 117
119
Replace Temp with Query 120
Introduce Explaining Variable 124
Split Temporary Variable 128
Remove Assignments to Parameters 131
Replace Method with Method Object 135
Substitute Algorithm 139
Chapter 7: Moving Features Between Objects 141
Move Method 142
Move Field 146
Extract Class 149
Inline Class 154
Hide Delegate 157
Remove Middle Man 160
Introduce Foreign Method 162
Introduce Local Extension 164
Chapter 8: Organizing Data 169
Self Encapsulate Field 171
Replace Data Value with Object 175
Change Value to Reference 179
Change Reference to Value 183
Replace Array with Object 186
Duplicate Observed Data 189
Change Unidirectional Association to Bidirectional 197
Change Bidirectional Association to Unidirectional 200
Replace Magic Number with Symbolic Constant 204
Encapsulate Field 206
Encapsulate Collection 208
Replace Record with Data Class 217
Replace Type Code with Class 218
Replace Type Code with Subclasses 223
Replace Type Code with State/Strategy 227
Replace Subclass with Fields 232
