Refactoring 101 - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Refactoring 101

Description:

Supports creating and running test suites. Available for Java & several other languages ... Anything by Jon Bentley - Programming Pearls, More Programming Pearls, ... – PowerPoint PPT presentation

Number of Views:54
Avg rating:3.0/5.0
Slides: 17
Provided by: u014
Category:

less

Transcript and Presenter's Notes

Title: Refactoring 101


1
Refactoring 101
  • William C. Wake
  • William.Wake_at_acm.org
  • 2-2-2000

2
Refactoring
3
Agenda
  • Code smells
  • Solid set of unit tests
  • Refactorings
  • Demo
  • Questions/Discussion

4
Code SmellsIf it stinks, change it.
  • Duplicate code
  • Switch statements
  • Long method
  • Large class
  • Data class (data bag)
  • Long parameter list
  • Primitive obsession
  • Temporary field
  • etc.

5
Unit Tests
  • Automatic
  • Self-checking
  • Run often (almost constantly)
  • If you want to refactor, the essential
    precondition is having solid tests. -- M. Fowler

6
JUnit
  • Unit testing tool
  • Supports creating and running test suites
  • Available for Java several other languages
  • http//xprogramming.com

7
Refactorings
  • Fowlers book has a catalog
  • There are many more
  • Often reversible
  • Pay attention to the mechanics
  • Let the compiler tell you
  • Small steps with constant tests

8
Extract Method
9
Encapsulate Field
10
Introduce Null Object
11
Parameterize Method
WebService
WebService
handleGet()
handle(serviceType,)
handlePut()
12
Replace Constructor with Factory Method
13
Replace String with Stringbuffer
14
Demo
  • Hand out real code seeded with refactoring
    opportunities
  • Audience takes 5 minutes to identify smells
  • Audience helps refactor in IDE
  • Observe the motion back and forth between test
    and code

15
Discussion
Questions?
16
More Information
  • Refactoring, by Martin Fowler
  • Extreme Programming Explained, by Kent Beck
  • Anything by Jon Bentley - Programming Pearls,
    More Programming Pearls, Writing Efficient
    Programs
Write a Comment
User Comments (0)
About PowerShow.com