|
Red Squirrel Reflections
Dave Hoover explores the psychology of software development
|
[Previous entry: "Underlying Values"] [Main Index] [Next entry: "Refactoring my Refactoring"]
Refactoring Train
Tuesday, October 1, 2002
I am studying Martin Fowler's Refactoring for the Chicago Agile Lunchtime Study Group. Roman and I are learning Ruby together and I have been playing with a little toy Train module. This morning as I was riding to work (on the train), I was playing with the Train module, using RubyUnit, and developing a sample client (UnionPacific.rb). I had the Refactoring book open next to me and was switching back and forth between coding and reading. As the train pulled into Chicago, I was pleased to have implemented a new refactoring: Replace Exception with Test.
Rather than have Train raise an exception when clients added Cars while the Train was moving, I pushed that responsibility onto the client. Clients can easily check the Train's speed through the speed method before they attempt to add Cars.
This shortened Train's addCar method to one line and kept the client code the same length. Through this simple example I caught a glimpse of how repeated microscopic refactorings can have a macroscopic effect.
Powered by Greymatter