Open rain1024 opened 10 years ago
// Before refactoring
void printOwing(double mount){
printBanner();
// print details
WriteLine("name: " + name);
WriteLine("amount: " + amount);
}
// After refactoring
void printOwing(double mount){
printBanner();
printDetails();
}
void printDetails(double mount){
WriteLine("name: " + name);
WriteLine("amount: " + amount);
}
The Rule of Three
Fowler, M. and Beck, K. (1999). Refactoring. 1st ed. Reading, MA: Addison-Wesley.
Duplicated Code | Long Method | Large Class | Long Parameter List | Divergent Change | Shotgun | Surgery | Feature Envy | Data Clumps | Primitive Obsession | Switch Statements | Parallel Inheritance | Hierarchies | Lazy Class | Speculative Generality | Temporary Field | Message Chains | Middle Man | Inappropriate Intimacy | Alternative Classes with Different Interfaces | Incomplete Library Class | Data Class | Refused Bequest | Comments
Composite Methods
Moving Features Between Objects
Organizing Data
Simplifying Conditional Expressions
Making Method Calls Simpler
Dealing with Generalization
Big Refactorings
Process
First Step: build a solid set of tests
References