<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                #### 命令模式 在軟件設計中,我們有時需要向某些對象發送請求(命令),但是對于請求(命令)發送者來說,并不知道請求(命令)的接收者是誰,它只需要發送命令即可;對于請求(命令)的接受者來說,他也并不知道給他發送請求(命令)的是誰,它只需要在有請求(命令)時執行自己的 action 即可。具體的請求(命令)發送者和接受者,我們就可以根據自己的需求自由組合。使得請求發送者與請求接收者消除彼此之間的耦合,讓對象之間的調用關系更加靈活。 主要特點就是將一個請求封裝為一個對象,從而使我們可用不同的請求對客戶進行參數化;對請求排隊或者記錄請求日志,以及支持可撤銷的操作。命令模式是一種對象行為型模式,其別名為動作(Action)模式或事務(Transaction)模式。 `角色` Command: 抽象命令類 ConcreteCommand: 具體命令類 Invoker: 調用者 Receiver: 接收者 Client:客戶類 `UML類圖` ![此處輸入圖片的描述](https://doc.shiyanlou.com/document-uid108299labid2297timestamp1486375353023.png) `示例代碼`:`Command.class.php` ~~~php <?php class Receiver { public function Action() { echo "Receiver->Action"; } } abstract class Command{ protected $receiver; function __construct(Receiver $receiver) { $this->receiver = $receiver; } abstract public function Execute(); } class MyCommand extends Command { function __construct(Receiver $receiver) { parent::__construct($receiver); } public function Execute() { $this->receiver->Action(); } } class Invoker { protected $command; function __construct(Command $command) { $this->command = $command; } public function Invoke() { $this->command->Execute(); } } $receiver = new Receiver(); $command = new MyCommand($receiver); $invoker = new Invoker($command); $invoker->Invoke(); ~~~
                  <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>

                              哎呀哎呀视频在线观看