Command design mode-learning Summary

Source: Internet
Author: User

Intent:

Encapsulate a request as an object so that you can parameterize the customer with different requests, queue requests or record request logs, and support unrecoverable operations.

Applicable environment:

(1) abstract the action to be executed to parameterize an object. You can use the callback function in the process language to express this parameterization mechanism. A callback function is a function that is registered at a certain place and will be called at a later time. The command mode is an object-oriented alternative to the callback mechanism.

(2) specify, sort, and execute requests at different times. A command object can have a lifetime unrelated to the initial request. If the recipient of a request can be expressed in a way unrelated to the address space, the command object responsible for the request can be sent to another different process and implemented there.

(3) cancel the operation. The Command's excute operation can store the status before the operation is implemented. when the operation is canceled, this status is used to eliminate the impact of this operation. You must add a unexcute operation to the command interface. This operation cancels the effect of the last excute call. The executed command is stored in a history list. You can traverse the list backward and forward, and call unexcute and excute respectively to "cancel" and "redo" the number of duplicates is unlimited ".

(4) logs can be modified so that the modifications can be redone when the system crashes. Add the loading and storage operations to the command interface to maintain a consistent change log. Recovery from a crash involves re-reading recorded commands from the disk and re-executing them with the excute operation.

(5) construct a system using high-level operations built on primitive operations. Such a structure is common in information systems that support transactions. A transaction encapsulates a group of changes to the data. Mode provides a method for modeling transactions. Command has a public interface that allows you to call all transactions in the same way. At the same time, it is easy to add new transactions to expand the system.

 

Structure:



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.