I have something named M, it has three states. When it is at one state, it should do something, then change to another one immediately. And my code can simply satisfy this, but it has a bad effect, at once it starts running, the function will never return.
So, how can I design this program?
class M {
State state;
func a() {
doSomethingA();
self.state = B;
b();
}
func b() {
doSomethingB();
self.state = C;
c();
}
func c() {
doSomethingC();
self.state = A;
a();
}
}
Aucun commentaire:
Enregistrer un commentaire