状态模式可以减少if else逻辑:
sudo pip install state
from state import stateful, state, behavior, switch
@stateful
class User(object):
class NeedSignin(State):
default = True
@behavior
def signin(self, usr, pwd):
...
switch(self, Player.Signin)
class Signin(State):
@behavior
def move(self, dst): ...
@behavior
def atk(self, other): ...