I am currently trying to implement an application where there are about 10 states. Unlike traditional state pattern where there is only 1 link to a different state from one state, I want it to be more like a directed graph where one state can have multiple edges to different states.
Example: I have states 1-10 ( vertexes). - are the edges. These can be the possible state transitions.
1-2, 1-3, 1-6 2-3, 2-9 3-5 4-3 5-2, 5-3, 5-4 6-3, 6-4,6-7, 6-9 ... And so on
Each states are classes, and each edges (the -) are methods. For example:
Class State1 { public void goToState2() ; public void goToState3() ; public void goToState6() ; }
Class State2 { public void goToState3() ; public void goToState9() ; }
...
I could think of reflection and bunch of switch statements to solve this problem, but I think I could also apply state pattern or come up with a more elegant solution here but I am absolutely stuck.
Any help or guidance would be appreciated!!
Aucun commentaire:
Enregistrer un commentaire