Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's not as subjective as it is more of a case by case decision. This example is quite misleading but polymorphic classes are sometimes useful when the domain grows, when you have have to update new behaviors all the time.. In that case then the switch becomes harder to maintain. Classes isolate behavior so new types don't modify existing code. I'd stick with switch statements in all the other cases. Sure, this could be abused and make simple things unnecessarily complicated but am just pointing out that there's a use-case for it.




Yeah, the problem is when people create extra classes just to avoid the switch statement.

Yes, I've seen this misused and it resulted in an over-complicated codebase with no benefit.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: