diff --git a/command/README.md b/command/README.md index d29c213cb..a5ff9a075 100644 --- a/command/README.md +++ b/command/README.md @@ -1,4 +1,4 @@ ---- + --- layout: pattern title: 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. ## 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. > 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 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 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. -* 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 space-independent way, then you can transfer a command object for the request to a different process and fulfill the request there. * 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 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 -un-execute and execute, respectively. +Unlimited-level undo and redo functionality is achieved by traversing this list backward and forward + calling un-execute and execute, respectively. * 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. -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. * 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 -to data. The Command pattern offers a way to model transactions. Commands have a common interface, +common in information systems that support transactions. A transaction encapsulates a set of data +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 system with new transactions. @@ -227,7 +227,7 @@ system with new transactions. * Implement callback 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) * [org.junit.runners.model.Statement](https://github.com/junit-team/junit4/blob/master/src/main/java/org/junit/runners/model/Statement.java) diff --git a/command/src/main/java/com/iluwatar/command/App.java b/command/src/main/java/com/iluwatar/command/App.java index 92e1a1e70..54ffeac44 100644 --- a/command/src/main/java/com/iluwatar/command/App.java +++ b/command/src/main/java/com/iluwatar/command/App.java @@ -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 * 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. * *

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