Very true!

That's exactly what I'm on about here.

There're too many examples in the wild doing crazy nested if-else branching when it could have been handled elegantly with the State pattern.

I know this article will upset a lot of if-else fanboiz. That's kinda the purpose.

Refactoring to State pattern is just one way to remove if-else branching. There're many other ways, depending on the concrete situation and goal.

Written by

Tech writer with 621K+ views. Sharing my opinion and what I learn. Danish C# backend engineer in FinTech. Ex Big4 senior tech consultant.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store