2 ms·
To some extent you can replace conditional logic with polymorphism in languages that support it (Java does). See, for example: https://refactoring.guru/replac
by mindcrime 4y ago
To some extent you can replace conditional logic with polymorphism in languages that support it (Java does).
See, for example:
https://refactoring.guru/replace-conditional-with-polymorphism https://refactoring.guru/replace-conditional-with-polymorphi...
Note that this can be made to work for simple conditionals. It's probably not going to help if you have really complicated conditions, the kind where you need to break out your old discrete math book and draw a truth table and use DeMorgan's Law and all of those other "rules of inference" to work out what happens.
Note also that there are (practical) limits to this in general. Creating lots of classes and overridden methods just to get rid of some conditional logic has the potential to make things even more byzantine and confusing, not less. But done well, and in limited doses, it can be a viable strategy.