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.