Java 设计模式之 命令模式(Command Pattern) 代码实现
306020
13年前
<pre class="brush:java; toolbar: true; auto-links: false;">public interface Command { public void execute(); }</pre> <pre class="brush:java; toolbar: true; auto-links: false;">public class Student implements Command { @Override public void execute() { System.out.println("学生执行。。。。"); } }</pre> <pre class="brush:java; toolbar: true; auto-links: false;">public class Teacher implements Command{ @Override public void execute() { System.out.println("老师执行"); } }</pre> <pre class="brush:java; toolbar: true; auto-links: false;">public class Test { public static void main(String[] args) { List<Command> list=new ArrayList<Command>(); list.add(new Student()); list.add(new Teacher()); for (Command commond : list) { commond.execute(); } } }</pre> <br />