1、IAction.java
package com.ssm.cts.pattern.state; public interface IAction { public void setState(int state); public void start(); public void stop(); }
2、Action.java
package com.ssm.cts.pattern.state; public class Action implements IAction { private int state; public void setState(int state) { this.state = state; } public void start() { System.out.println("启动"); } public void stop() { System.out.println("停止"); } }
3、Demo.java
package com.ssm.cts.pattern.state; public class Demo { // 测试 public static void main(String[] args) { IAction ation = new Action(); ation.setState(0); ation.start(); ation.stop(); } }