Hi Tomi Kaistila,
First of all, thanks for sharing your thoughts.
I respect your point, but I can't agree with it. I might think about over-engineering in the scope of this example only for this specific case as we're operating with the pure numbers without any computations (it was done for sake of simplicity) and only till the middle of the article because the second part of the article demonstrates how extendable is the current approach.
Let me share more thought on your comment:
...you got rid of the Switch statement but did you gain anything else?
- Of course, take a look at how the code is extendable now. (Open-Closed Principle)
...It still seems to take just as many or even more lines of code as with the Switch and on top of that it's not also obduscated.
- It's not about the number of lines but about code quality.
...I have admittedly not read Robert C. Martin's Clean Code book but this does not look clean to me.
- I strongly recommend reading this book as it's one of the best books ever written for developers.
...The same cannot be said for your approach.
- I wouldn't say it's my approach, but one of the existing patterns. I only demonstrated how flexible and extendable it is. Here are some other references where you can look up even more about the current pattern:
https://refactoring.guru/replace-conditional-with-polymorphism
https://zaengle.com/blog/replace-conditional-with-polymorphism