Grammatical fixes to command pattern

This commit is contained in:
Ilkka Seppälä 2021-06-09 08:05:24 +03:00
parent bbdff14a66
commit 7a46174391
No known key found for this signature in database
GPG Key ID: 31B7C8F5CC412ECB
2 changed files with 11 additions and 11 deletions

View File

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

View File

@ -26,7 +26,7 @@ package com.iluwatar.command;
/** /**
* The Command pattern is a behavioral design pattern in which an object is used to encapsulate all * The Command pattern is a behavioral design pattern in which an object is used to encapsulate all
* information needed to perform an action or trigger an event at a later time. This information * information needed to perform an action or trigger an event at a later time. This information
* includes the method name, the object that owns the method and values for the method parameters. * includes the method name, the object that owns the method, and values for the method parameters.
* *
* <p>Four terms always associated with the command pattern are command, receiver, invoker and * <p>Four terms always associated with the command pattern are command, receiver, invoker and
* client. A command object (spell) knows about the receiver (target) and invokes a method of the * client. A command object (spell) knows about the receiver (target) and invokes a method of the