Download presentation
Presentation is loading. Please wait.
1
Refactoring 101 William C. Wake William.Wake@acm.org 2-2-2000
2
Refactoring
3
Agenda l “Code smells” l Solid set of unit tests l Refactorings l Demo l Questions/Discussion
4
Code Smells “If it stinks, change it.” l Duplicate code l Switch statements l Long method l Large class l Data class (“data bag”) l Long parameter list l Primitive obsession l Temporary field l etc.
5
Unit Tests l Automatic l Self-checking l Run often (almost constantly) l “If you want to refactor, the essential precondition is having solid tests.” -- M. Fowler
6
JUnit l Unit testing tool l Supports creating and running test suites l Available for Java & several other languages l http://xprogramming.com
7
Refactorings l Fowler’s book has a catalog l There are many more l Often reversible l Pay attention to the mechanics l Let the compiler tell you l Small steps with constant tests
8
Extract Method
9
Encapsulate Field
10
Introduce Null Object
11
Parameterize Method WebService handleGet(…) handlePut(…) handle(serviceType,…)
12
Replace Constructor with Factory Method
13
Replace String with Stringbuffer
14
Demo l Hand out real code seeded with refactoring opportunities l Audience takes 5 minutes to identify smells l Audience helps refactor in IDE l Observe the motion back and forth between test and code
15
Discussion Questions?
16
More Information l Refactoring, by Martin Fowler l Extreme Programming Explained, by Kent Beck l Anything by Jon Bentley - Programming Pearls, More Programming Pearls, Writing Efficient Programs
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.