Overview
Wake addresses the complex conditional situation as a Special Case code smell with two symptoms - a complex if statement and/or value checking before doing the actual work [1].
Causation
There was a need for a special case to handle. A hotfix that was never adequately fixed could also be the reason for the smell.
Problems
📖
Comprehensibility
The method is doing a specific task, but there is "one special case" to consider.
🧩
Increased Test Complexity
Special case has to have an extra special test.
Example
Smelly
1def parse_foo(foo: Foo) -> Goo:
2 if 'zoo' in foo.sample_attribute:
3 ...
4 ...
5 ...
6
7 ...
8 ...
9 ...
10 ...Exceptions
Recursive methods always have to have a base case to stop the recursion.
---
Refactoring
- Consolidate Conditional Expression
- Replace Conditional with Polymorphism
- Introduce Null Object
- Replace Exception with Test
Sources
- ORIGIN2004 · ISBN 978-0321109293