4 ms·
Hmm...polymorphism is almost invariably simpler than if/else or switch/case, so not seeing the contradiction.
by mpweiher 5y ago
Hmm...polymorphism is almost invariably simpler than if/else or switch/case, so not seeing the contradiction.
- fortylove 5y agoIs that view not subjective though? Might someone think that if/else is simpler?
- qayxc 5y agoDepends entirely on the metric used. Cyclomatic complexity would put if/else behind polymorphism while using lines of code and depth of inheritance would favour the if/else way. That's the crux with software - there's not always an objectively better solution in terms readability/comprehensibility and some metrics that try to capture these qualities are inherently at odds with each other.
- ajuc 5y agoI've seen this happening a lot: - you have the same if-then-else in 3 places in code with 3 different effects - you refactor it to polimorphism (Enum with a few overloaded methods works well in java) - now one of these places need additional condition so you make it a little more complex - year passes - you have eldritch abomination of OOP instead of 3 if-then-elses with slightly different conditions because at no point someone was brave enough to refactor back into if-then-elses as the special cases piled up
- ziml77 5y agoExactly my experience with polymorphism. It starts out looking super clean but then the business requirements shift and each has its own edge cases that turn it into a giant mess, often ending up as a mix of both polymorphism and convoluted if statements.
- deleted 5y ago[deleted]