Cover page by Don Roberts, William Opdyke, Kent Beck, Martin Fowler, John Brant

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Chapter 9. Simplifying Conditional Expressions

Conditional logic has a way of getting tricky, so here are a number of refactorings you can use to simplify it. The core refactoring here is Decompose Conditional (238), which entails breaking a conditional into pieces. It is important because it separates the switching logic from the details of what happens.

The other refactorings in this chapter involve other important cases. Use Consolidate Conditional Expression (240) when you have several tests and all have the same effect. Use Consolidate Duplicate Conditional Fragments (243) to remove any duplication within the conditional code.

If you are working with code developed in a one exit point mentality, you often find control flags that allow the ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required