July 16, 2010

...Learn TDD with Codemanship

Codemanship's Code Smell Of The Week - Switch Statements

Switch statements are bad from an OO design standpoint. Not only because they're basically big nested IF statements, but because they have a tendency to grow. A refactored switch statement would exploit polymorphism, which is the OO way to make decisions about how to do specific "stuff" at run time.

Jason Gorman demonstrates how he refactors a simple switch statement into a polymorphic OO solution (like the Strategy Pattern).

Part I

Part II

Download the source from http://bit.ly/8Y71ik

For training and coaching in refactoring, OO design and TDD, visit http://www.codemanship.com

Posted 10 years, 10 months ago on July 16, 2010