Command design pattern for C # design mode (Order design mode)

Source: Internet
Author: User

Commands (command) mode

The command mode belongs to the behavior pattern "GOF95" of the object. Command mode is also known as action mode or transaction (Transaction) mode. The command mode encapsulates a request or operation into an object. The command mode allows the system to parameterize clients using different requests, queuing up requests, or logging request logs, which provides the ability to undo and restore commands.

The command mode is the encapsulation of the command. The command mode divides the responsibility for issuing the command from the responsibility of executing the command and delegating it to different objects.

Each command is an action: the requesting party makes a request to perform an action, the receiving party receives the request, and executes the action. The command mode allows the requesting party to be independent of the receiving party, making it unnecessary for the requesting party to know the interface of the party receiving the request, not to mention how the request was received, and whether the operation was executed, when it was executed, and how it was executed.

II. structure of the command pattern

The class diagram for the command mode is as follows:

The command mode involves five roles, each of which is:

Client role: Creates a specific command (Concretecommand) object and determines its recipient.

Command role: Declares an abstract interface to all specific command classes. This is an abstract role.

The specific command (Concretecommand) role: Defines a weak coupling between the receiver and the behavior, implements the Execute () method, and is responsible for invoking the corresponding operation to receive the test. The Execute () method is often called a practice method.

Requester (Invoker) role: is responsible for invoking the Command object execution request, the related method is called the action method.

Recipient (Receiver) role: be responsible for implementing and executing a request specifically. Any class can be a receiver, and the method of implementing and executing the request is called the action method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.