Beware type switches
From CSSEMediaWiki
(Difference between revisions)
Line 1: | Line 1: | ||
This is Reil's heuristic #5.12 | This is Reil's heuristic #5.12 | ||
− | |||
− | |||
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. | 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. |
Revision as of 01:07, 22 July 2008
This is Reil's heuristic #5.12
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]