RSS feed
[root]
/
c06
/
code
/
TI Pattern
/
software design
/
document
strategy
login:
password:
title search:
Search this site
Enter your search terms
Web
www.carfield.com.hk
Submit search form
Prev
Next
Wed Dec 26 16:00:00 GMT 2001
CommandPattern
//: c06:CommandPattern.java import java.util.*; import com.bruceeckel.test.*; interface Command { void execute(); } class Hello implements Command { public void execute() { System.out.print("Hello "); } } class World implements Command { public void execute() { System.out.print("World! "); } } class IAm implements Command { public void execute() { System.out.print("I'm the command pattern!"); } } // An object that holds commands: class Macro { private List commands = new ArrayList(); public void add(Command c) { commands.add(c); } public void run() { Iterator it = commands.iterator(); while(it.hasNext()) ((Command)it.next()).execute(); } } public class CommandPattern extends UnitTest { Macro macro = new Macro(); public void test() { macro.add(new Hello()); macro.add(new World()); macro.add(new IAm()); macro.run(); } public static void main(String args[]) { new CommandPattern().test(); } } ///:~
(google search)
(amazon search)
1
2
3
second
download zip of files only
Prev
Next