Ref: Refactoring — Improving the Design of Existing Code, by Martin Fowler, Addison-Wesley, 2000, ISBN 0-201-48567-2

"Refactoring" has become a buzzword. We don't say we're fixing our dreadful, messy code anymore, we say we're "refactoring" it. Sounds more dignified. But there is something to this notion, namely, that there is much greater depth to the business of producing quality code than meets the eye. Getting from first-pass code, even code that has been debugged, to true quality code is a lot more complicated than people realize. Even very experienced people may be cavalier and casual about the code they write, as if revisiting it were some kind of admission of incompetence.

There are several points to make about how we can existing improve code.

This last point is the most important. We should invest the time it takes to revisit our designs in order to save time later. The investment has the prospect to bring a huge payoff. Remember, the time invested in maintaining code is significantly greater, on average, than the time invested in creating the software in the first place.
Case Study: Video Rental System
Adapted from Chapter 1 of Martin Fowler's Refactoring
Initial Code Base: First Refactoring: Second Refactoring: Third Refactoring: Fourth Refactoring: Fifth Refactoring: Sixth Refactoring: