.Net設計模式執行個體之命令模式(Command Pattern)

來源:互聯網
上載者:User

一、命令模式簡介(Brief Introduction)

命令模式(Command Pattern)將請求封裝為一個對象,從而使你用不同的請求對客戶進 行參數化,對請求排隊或紀錄請求日誌,以及支援可撤銷的操作。

Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations

二、解決的問題(What To Solve)

當需要有撤銷或者恢複操作時,可以考慮使用命令模式。

三、命令模式分析(Analysis)1、命令模式結構

Command抽象類別:聲明一個介面,用於執行操作,declares an interface for executing an operation。

ConcreteCommand實作類別:將一個接收者對象綁定到一個動作。調用接收者相應的操作, 以實現Execute 。

defines a binding between a Receiver object and an action

implements Execute by invoking the corresponding operation(s) on Receiver。

Receiver類:知道如何執行一個請求相關的操作。knows how to perform the operations associated with carrying out the request.

Invoker類:要求命令執行一個請求。asks the command to carry out the request 。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.