In my code I'm evaluating 3 booleans.
Each combination of those booleans truth value requires different action (for example, different method should be executed).
Currently I'm using if-else block (8 options, not that nice).
I'm wondering if there's another option to write this code which will make it 'prettier'.
Maybe design pattern?
Someone has an idea?
use a switch block
switch ((A?4:0) + (B?2:0) + (C?1:0)){
case 0: //A,B,C false
break;
case 3: //A False, B,C true
break;
case 4: //A True, B,C false
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With