<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ### 命令模式 將一個請求封裝為一個對象,從而使你可用不同的請求對客戶進行參數化;對請求排隊或記錄請求日志,以及支持可撤銷的操作。(摘抄) 命令模式我感覺結合代碼來講會比較好講,所以我先寫代碼把 ~~~ import java.util.ArrayList; import java.util.List; //Action類,執行具體的操作 public class Action { void actionA() { System.out.println("A"); } void actionB() { System.out.println("B"); } } //Command類,用來聲明執行操作的接口 public abstract class Command { Action action; public Command(Action action) { this.action = action; } public abstract void execute(); } public class ConcreteCommandA extends Command { public ConcreteCommandA(Action action) { super(action); } @Override public void execute() { // TODO Auto-generated method stub action.actionA(); } } public class ConcreteCommandB extends Command { public ConcreteCommandB(Action action) { super(action); } @Override public void execute() { // TODO Auto-generated method stub action.actionB(); } } //Invoker類,要求該命令執行這個操作 public class Invoker { private List<Command> commands = new ArrayList<Command>(); //在add和delete方法中可以執行排隊請求和記錄日志和否決請求操作 public void addCommand(Command command) { commands.add(command); } public void deleteCommand(Command command) { commands.remove(command); } public void executeCommand() { for (Command command : commands) { command.execute(); } } } class Client { public static void main() { Action action = new Action(); Command aCommand = new ConcreteCommandA(action); Command bCommand = new ConcreteCommandB(action); Invoker invoker = new Invoker(); invoker.addCommand(aCommand); invoker.addCommand(bCommand); invoker.deleteCommand(aCommand); invoker.executeCommand(); } } ~~~ 一個命令模式的模板差不多就是這樣了,從這個模板可以很清晰的看出來要添加新的命令也十分容易,刪除也很容易,添加新的命令類,更是這里的一大亮點,當你需要一個ConcreteCommandC來同時執行actionA和actinoB那么新建一個ConcreteCommandC類就可以了,在execute方法中,添加這兩個方法的執行就ok,對于設計模式的一些原則運用得十分到位。 命令模式把請求一個操作的對象與知道怎么執行一個操作的對象分隔開了。(摘抄) ### 命令模式的作用 1.它能較容易地設計一個命令隊列。 2.在需要的情況下,可以較容易地將命令記入日志。 3.允許接受請求的一方決定是否要否決請求。 4.可以容易的實現對請求的撤銷和重做。 5.由于加進新的具體命令類不影響其他的類,因此添加新的具體命令類很容易。 (摘抄) ### 注意 敏捷開發原則告訴我們,不要為代碼添加基于猜測的,實際不需要的功能。如果不清楚一個系統是否需要命令模式,一般就不要急著去實現它,事實上,在需要的時候通過重構實現這個模式并不困難,只有在真正需要如撤銷/恢復操作等功能時,把原來的代碼重構為命令模式才有意義。(摘抄)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看