design_model(17)state
1.状态模式
根据其内部状态改变其行为
2.实例
public interface State { void handle(); } public class GoodState implements State{ @Override public void handle() { System.out.println("goodstate"); } } public class Context { private State state; public void setState(State s) { System.out.println("修改状态!"); state = s; state.handle(); } } public class Client { public static void main(String[] args) { Context context = new Context(); context.setState(new GoodState()); } }