Beware type switches
From CSSEMediaWiki
Revision as of 01:07, 22 July 2008 by Kris Nicholson (Talk | contribs)
This is Reil's heuristic #5.12
It should be explained here.
Type switches involve changing behaviour based on the object's type. Problems occur when multiple switches occur over the same variable in the same class, since when one is modified, all occurrences may need to be changed.
A possible solution is to replace any type code with a type class or Strategy pattern. See Martin Fowler's example at [Replace Type Code With State/Strategy]