小A:“命令模式怎樣與其它模式的配合使用?”
大B:“1、看上邊的Invoker的實現是否很像代理模式呢,Invoker的這種實現其實就是一種代理模式。2、需求:有個固定命令組合會多次被執行。解決:加入合成模式,實現方法如下,定義一個宏命令類。”
publicclassMacroCommandimplementsCommand{
privateListcmdList=newArrayList();
publicadd(Commandmand){
cmdList.add(mand);
}
publicremove(Commandmand){
cmdList.remove(mand);
}
publicvoidexecute(){
Commandcmd;
for(inti=0;i