不太理解the design pattern java companion一书中的Command

已经建立了
class btnRedCommand extends Button implements Command {...}
class fileExitCommand extends MenuItem implements Command {..}
等等这些类
但注册的时候为什么还是用fileOpen(),fileExit()这些方法?这些方法是没有使用COMMAND模式之前所采用的方法呀!!
mnuOpen.addActionListener(new fileOpen());
mnuExit.addActionListener(new fileExit());
请指点!!!
具体请看http://www.patterndepot.com/put/8/command.pdf

Command是对行为进行封装,这里就是对fileOpen,fileExit这些命令的封装,这样一来,在actionPerformed()方法中就不必要知道具体是哪个命令,如:Command cmd = (Command)e.getSource();
cmd.Execute();--执行这个方法就行,具体是哪个方法,运行期回自动判断,也就是多态起了作用。
而new fileOpen(),我有些迷惑,fileOpen()是方法吗?感觉应该是个类。如果是类的话,这就是实际类型,也就是在运行期要具体调用的。

banq 大哥的讲述很清楚了,你可以看看。还有在petstore中的waf 中也有command模式,看看是如何实现的,很有实际意义!!


谢谢回答,其实我的困惑也就在new ....这里,我觉得是书上的错误

你看书的时候应该把整节看完,后面有
class fileExit implement ActionListener{
pulbic void actionPerformed(ActionEvent e){
.....
}
}

.....

也就是说这些 fileOpen; fileExit, btnRed 都是一些 对应的ActionListener.