IOS design mode Learning (20) command

Source: Internet
Author: User

1 Preface

In object orientation, commands are encapsulated in various command objects. Command objects can be passed and reused by different clients at the specified time. The well-designed design pattern is called the Command pattern.

2. Details

2.1 Brief Introduction

The command object encapsulates the information about how to execute commands on the target. Therefore, the client or caller can still perform any operations on the target without having to know any details about the target. By encapsulating a request into an object, the client can parameterize it and place it into the pair class or log, and also support unrecoverable operations. The command object binds one or more actions to a specific receiver. The command mode eliminates the binding between the action that acts as an object and the receiver that executes it.

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

2.2 When to use

(1) to allow the application to support revocation and restoration;

(2) You want to parameterize an action of an object to execute the operation, and replace the callback function with different command objects;

(3) specify, sort, and execute requests at different times;

(4) You want to record the modification logs so that these modifications can be redone later in case of system failure;

(5) to enable the system to support transactions, mistakes encapsulate a series of modifications to the data. Transactions can be modeled as command objects.

3 conclusion

The benefits of eliminating the coupling between commands, callers, receivers, and clients in applications are obvious. If a specific command needs to be modified in reality, most of the other components will not be affected. In addition, it is very easy to add a new command class, because you do not have to modify the existing class for this.

The above is all content and I hope it will help you.

 

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.