1
- ---
1
+ ---
2
2
layout: pattern
3
3
title: Command
4
4
folder: command
@@ -19,7 +19,7 @@ Encapsulate a request as an object, thereby letting you parameterize clients wit
19
19
requests, queue or log requests, and support undoable operations.
20
20
21
21
## Explanation
22
- Real world example
22
+ Real- world example
23
23
24
24
> There is a wizard casting spells on a goblin. The spells are executed on the goblin one by one.
25
25
> The first spell shrinks the goblin and the second makes him invisible. Then the wizard reverses
@@ -135,7 +135,7 @@ public class Goblin extends Target {
135
135
}
136
136
```
137
137
138
- Finally we have the wizard in main function who casts spell
138
+ Finally, we have the wizard in the main function casting spells.
139
139
140
140
``` java
141
141
public static void main(String [] args) {
@@ -202,22 +202,22 @@ Use the Command pattern when you want to:
202
202
* Parameterize objects by an action to perform. You can express such parameterization in a
203
203
procedural language with a callback function, that is, a function that' s registered somewhere to be
204
204
called at a later point. Commands are an object-oriented replacement for callbacks.
205
- * Specify, queue, and execute requests at different times. A Command object can have a lifetime
205
+ * Specify, queue, and execute requests at different times. A Command object can have a life
206
206
independent of the original request. If the receiver of a request can be represented in an address
207
207
space-independent way, then you can transfer a command object for the request to a different process
208
208
and fulfill the request there.
209
209
* Support undo. The Command' s execute operation can store state for reversing its effects in the
210
210
command itself. The Command interface must have an added un-execute operation that reverses the
211
211
effects of a previous call to execute. The executed commands are stored in a history list.
212
- Unlimited-level undo and redo is achieved by traversing this list backwards and forwards calling
213
- un-execute and execute, respectively.
212
+ Unlimited-level undo and redo functionality is achieved by traversing this list backward and forward
213
+ calling un-execute and execute, respectively.
214
214
* Support logging changes so that they can be reapplied in case of a system crash. By augmenting the
215
215
Command interface with load and store operations, you can keep a persistent log of changes.
216
- Recovering from a crash involves reloading logged commands from disk and re-executing them with
216
+ Recovering from a crash involves reloading logged commands from the disk and re-executing them with
217
217
the execute operation.
218
218
* Structure a system around high-level operations build on primitive operations. Such a structure is
219
- common in information systems that support transactions. A transaction encapsulates a set of changes
220
- to data . The Command pattern offers a way to model transactions. Commands have a common interface,
219
+ common in information systems that support transactions. A transaction encapsulates a set of data
220
+ changes . The Command pattern offers a way to model transactions. Commands have a common interface,
221
221
letting you invoke all transactions the same way. The pattern also makes it easy to extend the
222
222
system with new transactions.
223
223
@@ -227,7 +227,7 @@ system with new transactions.
227
227
* Implement callback functionality
228
228
* Implement the undo functionality
229
229
230
- ## Real world examples
230
+ ## Real- world examples
231
231
232
232
* [java.lang.Runnable](http:// docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html)
233
233
* [org.junit.runners.model.Statement](https:// github.com/junit-team/junit4/blob/master/src/main/java/org/junit/runners/model/Statement.java)
0 commit comments