java设计模式----状态模式 weir 2015-07-06 10:51:19.0 java,设计模式 1417 虽然二十多种设计模式都是前辈总结出来的精华,但我觉得精华有点多了,这个状态模式我就看不懂,也不是说不理解,而是不知道为什么会是这样,也许是我太浮躁了或者是我的专注程度不够吧。 package com.weir.state; public interface State { public void handle(String s); } package com.weir.state; public class Context { private State state; public void setState(State state) { this.state = state; } public void request(String s) { state.handle(s); } } package com.weir.state; public class AState implements State{ @Override public void handle(String s) { System.out.println("A"); } } package com.weir.state; public class BState implements State{ @Override public void handle(String s) { System.out.println("B"); } } package com.weir.state; public class Client { public static void main(String[] args) { State state = new AState(); Context context = new Context(); context.setState(state); context.request("doit"); } } 我觉得特没意思的一个模式。说白了就是控制一个事物的状态变化。