Skip to content

Latest commit

 

History

History
30 lines (17 loc) · 1.69 KB

File metadata and controls

30 lines (17 loc) · 1.69 KB

Command Processor

Scenario

See Command.

Choice of Pattern

In this scenario we want to apply the Command Processor Pattern to execute requests to the application. The command processor acts on behalf of the clients and within the constraints of the application (POSA).

Test

We have identified "typing text" (append/delete letters) as actions (commands) that shall support undo. So the command processor needs to manage sequences of executing, undoing and redoing commands.

Test

The text processing logic behind the text component now maintains undo and redo stacks. Typing anything is represented by an AppendTextCommand or a DeleteTextCommand and goes to the undo-stack. By clicking undo, the last command on the stack gets compensated and then goes to the redo-stack. For redo, the logic works vice-versa.

Try it out!

Open CommandProcessorTest.java to start playing with this pattern. By setting the log-level for this pattern to DEBUG in logback.xml you can watch the pattern working step by step.

Remarks

  • The biggest challenge (for the command processor) is executing a command (deferred) within the constraints of the application. As mentioned in Command this can be quite tricky.

References

  • (POSA) Buschmann, F., Meunier, R., Rohnert, H., Sommerlad, P., Stal, M.: Pattern-Oriented Software Architecture: A System of Patterns. Wiley (1996)