Refactoring – decompose conditional

Complex conditional logic is tricky to debug.

It may seem obvious initially but when you land at the start with an edge case it can be a time sink hole. Especially if you keep on hitting it.

And the more and deeper nested you get the more complex it becomes.

Decompose Conditional is a simple design pattern that takes a complicated if/then/else statement and pulls it apart.

The condition is put in its own method.

And so are the then / else parts.

Extract the conditional and each leg as follows:

Leave a Reply

Your email address will not be published. Required fields are marked *