State-dependent behaviour of Python objects using Ruby-like eigenclasses with mixins
问题 I've been looking for a natural way to implement state-dependent behaviour (state machines) in Python objects. The goal was for objects to have a small number of states, or "mutually orthogonal" aspects of state, which would determine their concrete behaviour at each moment. In other words, the method returned by x.foo should be determined by the current state of x , and if x changes its state, the implementation of some or all of its methods should change accordingly. (I think some call it