Refactoring Demo Screencast

Four ways to Extract Method.

Refactoring is "improving the design of existing code". We want to do this quickly and safely, so that we're improving the code's design but not introducing bugs while we change it.

This series of videos shows four different ways of performing the refactoring "Extract Method":

The code we're improving is part of a program that lets a user unscramble sentence fragments. The part in bold below shows the code we're going to extract.

public class Board extends JPanel implements PropertyChangeListener {
    // ...

    public String toString() {
        Component[] cards = this.getComponents();
        List sortedResult = Arrays.asList(cards);
        Collections.sort(sortedResult, new BoardComparator()); 

        StringBuffer result = new StringBuffer();
        for (int i = 0; i < sortedResult.size(); i++)
            result.append(sortedResult.get(i).toString());

        return result.toString();            

    }
}
  1. Sloppy (Flash, 0.9M)
  2. Manual, but "by the book" (Flash, 1.1M)
  3. Automated, using the IDE's refactoring support (Flash, 0.9M)
  4. Automated, at full speed (Flash, 0.5M)

Sloppy

Manual

Automated

Automated, At Speed

[Recorded May, 2006. Tools: Eclipse, Macromedia Captivate, Audacity.]

This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Comments are closed.