Simplifying Conditional Expressions
Making logic easier to read.
Table of Contents
- Decompose Conditional: Decompose the complicated parts of the conditional into separate methods.
- Consolidate Conditional Expression: Combine multiple conditionals that lead to the same result.
- Consolidate Duplicate Conditional Fragments: Move the code that is identical in all branches of the conditional to outside of the conditional.
- Replace Nested Conditional with Guard Clauses: Use guard clauses for all the special cases.
- Replace Conditional with Polymorphism: Move each leg of the conditional to an overriding method in a subclass.