Lift-up Conditional

This refactoring was named by Emily Bache. She first learned it from Llewellyn Falco.

Examine

Look for a complex conditional that has a condition that is duplicated in more than one place. This is the conditional you will ‘lift up’ to be only in one place at the top. Note - in this process another conditional might become duplicated instead, so it doesn’t always help.

Prepare

Copy the section of code containing the conditional.

Implement

Clear

Check whether the conditional really is simpler now, if not revert.

Follow up

Once the conditional is clearer, consider extracting and naming parts of it.

Prompted by Code Smells

Relevant Learning Hours

Sources

Back to All Refactorings