"Design Mode Design Pattern" Reading Notes

xiaoxiao2021-03-06  21

"Design Mode Design Pattern" Reading Notes

Command mode

structure

purpose

The Command object establishes the connection between the command issuer (Invoker) and Receiver. Thus, INVOKER does not need to know who is Receiver, which only issues an Execute () request to Command, and Command automatically tells Receiver for the corresponding processing.

discuss

1. If Command needs undo / redo operation, you need to save various states, you can use the MEMENTO mode; if it is a string undo / redo command, then you need to connect these Command into a history list, if these Command is in the execution Will change, then you need Copy to History List, instead of using REFERENCE, you can use the prototype mode for COPY operations at this time.

2, if Command is simple, just establish the connection between Invoker and Receiver, you can use the template to make a universal Command template.

3, Composite mode can be used to implement Macrocommands (Collection of Command).

Reference

"Design Pattern" Gang-Of-4 1997

转载请注明原文地址:https://www.9cbs.com/read-43166.html

New Post(0)