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.

Software Developer Manager | Big4 ex. FinTech | Writer with +1M views. Sharing my opinion & what I learn. YT channel youtube.com/c/NicklasMillard

Love podcasts or audiobooks? Learn on the go with our new app.

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