Académique Documents
Professionnel Documents
Culture Documents
Lasse Koskela
Chapter 3: Refactoring in Small Steps
Paul Ammann
http://cs.gmu.edu/~pammann/
Overview
Exploring a Potential Solution
Changing Design in a Controlled Manner
Taking the New Design Further
3/4/17
Get Smarter On The Side, Then Apply 4
Changing Design in Controlled Manner
Creating an Alternative Implementation
Starting With the Low Hanging Fruit
TDD Development of a Template Parser
Removing Duplication From Tests
Refactoring Is Always Important
Applying Learning From the Spike
Final Code Version (note Segment class, originally String)
private void append(String segment, StringBuilder result) {
if (isVariable(segment) { evaluateVariable(segment, result); } // dispatching
else { result.append(segment);}
}
Koskela Refactors Substantially
TemplateParse.java
3/4/17
Now We Can Parse; Next Step Is To Use Parser 5
Changing Design in a Controlled
Manner - Continued
Switching Over Safely
Adopting the New Implementation
Recoding the evaluate() method
Cleaning Up By Extracting Methods
Pull Out The Old Stuff That s No Longer Relevant
Result is new Template Class
Template.java