On specific states I have to perform some actions. I am not happy with current solution where I check if the whole 4D vector matches. Are there any known design patterns which could help me to make this code look better?
Let's say that our state is [X1, X2, B1, B2].
What I ended with is just a bunch of if
s which doesn't look great.
if(state == [1,2,a,b])
action1();
if(state == [1,3,c,d])
action2();
if(state == [2,4,e,f])
action1();
if(state in [[1,2,a,c], [1,5,g,g]])
action1();
//etc...
I am not sure if there is anything that could be done better, but if there is please let me know
Aucun commentaire:
Enregistrer un commentaire