Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the command mode in java

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use the command mode in java". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the command mode in java".

1. Definition of pattern

Several processes of booting the computer: 1. Load power 2. Equipment check 3. Loading system

The client just wants to issue a command or request, does not care who the real recipient of the request is, nor does it care how to implement it, and the action of the same request can have different request contents, and of course, the specific processing functions are also different. how to achieve it?

Definition of command mode: encapsulate a request as an object so that you can parameterize customers with different requests; queue or log requests; and support undoable operations.

2. UML diagram

Command: defines the interface of the command and declares the method to execute

ConcreteCommand: the command interface object, which usually holds the receiver and calls the receiver's function to complete the operation to be performed by the command

Receiver: the recipient, the object that actually executes the command

Invoker: requires the command object to execute the request, usually holds the command object, and can hold a lot of command objects. This is where the client really triggers the command and requires the command to perform the corresponding action.

Client: create a specific command object and set the recipient of the command object.

Code:

3. Grinding design mode

1) the key of command mode: encapsulate the request into an object, that is, a command object, and define a unified interface to perform operations, which can be stored, forwarded, recorded, undone and processed, etc.

2) Parametric configuration: customer requests can be parameterized with different command objects.

For example, the restart and start buttons, although the same button is pressed, which is equivalent to the same request, different button objects are configured for the request, and different functions are performed.

3) the meaning of an undoable operation: abandon the operation and return to the state before the operation was performed.

Two ways of thinking: 1. Compensation type 2. Storage recovery type

4) Macro command: a command that contains multiple commands, which is a combination of commands.

5) queue request: queue the command object to form a work queue, and then take out the command object in turn to execute.

6) Log request: the historical record of the request is saved, which is usually stored permanently.

7) the essence of command mode: encapsulate the request, encapsulate the request object into a command object, and then perform a series of processing on this object.

Thank you for your reading, the above is the content of "how to use the command mode in java". After the study of this article, I believe you have a deeper understanding of how to use the command mode in java, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report