What does that ‘if’ mean?

Muhammad Durrah
2 min readJun 27, 2019

While I was working on fixing a bug today, I came across with a method containing a conditional check to execute some updates on some business object. It was like:

and because this resulted to a bug I had to understand and imagine the intention of this code’s author when he/she wrote it.

Okay, then I spent some time to understand what he wanted. And because I like refactoring I thought of how to make this check make more sense, the refactoring for this is almost direct and clear, simply by presenting a name for the sub-conditions like:

or even by combining sub-conditions:

Sometimes I go more crazy by providing a long, but expressive name (this is from another case :) )

Returning to the first example I personally prefer encapsulating these condition checks inside the business object itself:

and the someMethod would be then:

Other techniques also works like wrapping the SomeBO class with a small wrapper and move conditional methods there.

The take away here is:
- Use meaningful names for your parameters, methods and even conditions
- Business Object can be more than simple POJO, we can make it express itself more.

--

--