Hi Wim,

Thanks a lot for taking the time to read and respond to my article. Any reader is much appreciated :)

I purposely left switch cases out of this as they don’t solve the problem any better than if-else.

If you use switch cases and would need to extend your code, you’d have to go modify existing code just to account for the new feature. This is obviously a violation of OCP.

Example 5 perfectly illustrates how you’d go about extending your codebase without having to add new cases or else-ifs. But you’d of course need to place the discovery process outside the method it’s currently in.

Please refrain from ever teaching junior developers that if-else is a perfectly viable solution to extensible software.

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