
publicclassContext{ //持有一个State类型的对象实例 privateState state; //更新状态 publicvoid setState(State state){ this.state = state; } //用户感兴趣的接口方法 publicvoid request(String sampleParameter){ //转调state来处理 state.handle(sampleParameter); }}原文:http://www.cnblogs.com/Doing-what-I-love/p/5621158.html