Design mode--Command mode

Source: Internet
Author: User

Defined:

Command mode, which encapsulates a request as an object so that you can parameterize the client with different requests;

Queue or log request logs for requests, and support for actions that can be undone.

Role:

First, it can design a command queue more easily;

Second, in the case of need, it can be easier to complete the command into the log;

Third, allow the party receiving the request to decide whether to request it;

Finally, the cancellation and redo of the request can be realized easily;

The addition of the new specific command class does not affect the other classes, so it is easy to add new specific command classes.

Key advantages: The command mode is to request an action object with an object that knows how to perform an operation to split the grill.

Agile development principles tell us not to add guesswork-based, physically unwanted functionality to your code.

If it is not clear whether a system requires command mode, it is generally not urgent to implement it, in fact, it is not difficult to implement this mode by refactoring when needed, only when it really needs functions such as undo/redo operations.

Refactoring the original code into a command pattern makes sense.

Design mode--Command mode

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.