Java Tip: 实现Command模式[5]

[入库:2005年8月19日] [更新:2007年3月25日]

本文简介:选择自 lostmouse 的 blog

command模式具有以下优点:

1. command将 "进行操作请求" 的对象和 "知道如何执行操作" 的对象分离开来(即,解耦)。

2. command是个很棒的对象。它可以象任何其它对象一样被使用和继承。

3. 多个command可以被组装成一个复合command。

4. 很容易增加新的command,因为不需要修改现有的类。

如果执行过的命令序列被保存在一个历史列表中,就可以遍历这个列表来提供undo和redo操作。要想实现这一功能,必须在command接口中有一个unexecute()操作。这一练习留给读者自己去完成。

---------------------------------------------------------------------------

相关资源
· design patterns by gamma, helm, johnson, vlissides, addison-wesley, 1994, isbn 0-201-63361-2 http://www.bookbuyer.com/cgi-bin/gettitle.cgi?isbn=0201633612

· dr. dobb's journal, january 1998: "java reflection: not just for tool developers," by paul tremblett http://www.ddj.com/articles/1998/9801/9801c/9801c.htm

· sun's reflection page
http://java.sun.com/docs/books/tutorial/reflect/index.html

· "the java language environment -- a white paper" (may 1996), by james gosling and henry mcgilton covers details about java's dynamic loading and binding mechanism
http://java.sun.com/docs/white/langenv/
for more on taking advantage of java's unique feature of dynamic loading and binding mechanism to build a dynamic and dynamically-extensible system, see
http://java.sun.com/docs/white/langenv/

本文关键:Command
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top