Conditional Complexity

Prev don't be afraid of buying books Next

Conditional logic is innocent in its infancy, when it is simple to understand and contained within a few lines of code. Unfortunately, it rarely ages well. For example, you implement several new features and suddenly your conditional logic becomes complicated and expansive. Several refactorings in Refactoring [F] and this catalog address such problems.

If conditional logic controls which of several variants of a calculation to execute, consider applying Replace Conditional Logic with Strategy (129).

If conditional logic controls which of several pieces of special-case behavior must be executed in addition to the class's core behavior, you may want to use Move Embellishment to Decorator (144).

If the conditional expressions that control an object's state transitions are complex, consider simplifying the logic by applying Replace State-Altering Conditionals with State (166).

Dealing with null cases often leads to the creation of conditional logic. If the same null conditional logic is duplicated throughout your system, you can clean it up by using Introduce Null Object (301).


Refactoring to Patterns (The Addison-Wesley Signature Series)
Refactoring to Patterns
ISBN: 0321213351
EAN: 2147483647
Year: 2003
Pages: 103

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: