LogFAQs > #959904564

LurkerFAQs, Active DB, DB1, DB2, DB3, DB4, DB5, DB6, DB7, DB8, Database 9 ( 09.28.2021-02-17-2022 ), DB10, DB11, DB12, Clear
Topic List
Page List: 1
Topicif conditions are an antipattern
Sahuagin
11/11/21 1:55:50 PM
#5:


chelsea_wtf posted...
thats why its so important to have an AbstractConditionFactory to create a variety of different IBooleanHandlers so that your conditional handling logic can be dependency-injected instead of hardcoded. just having an if statement in your business logic is basically two different unconditional jumps combined into a conditional jump
the right approach can be to put the logic from each of the if blocks into their own classes and simply call a method on the abstract class or interface.

this comes up a lot when for example switching on enum types. IMO enums are generally an anti-pattern since they don't allow for any polymorphism or code reuse and you end up with these "logic varies with value" areas all over the place when they should be in that type itself instead.

---
... Copied to Clipboard!
Topic List
Page List: 1