Command pattern

Using an invoker object allows bookkeeping about command executions to be conveniently performed, as well as implementing different modes for commands, which are managed by the invoker object, without the need for the client to be aware of the existence of bookkeeping or modes.

The Command1 class implements the Command interface by performing an action on a receiver (receiver1.action1()).

The terminology used to describe command pattern implementations is not consistent and can therefore be confusing.

This is the result of ambiguity, the use of synonyms, and implementations that may obscure the original pattern by going well beyond it.

The program output is The first published mention of using a Command class to implement interactive systems seems to be a 1985 article by Henry Lieberman.

[4] The first published description of a (multiple-level) undo-redo mechanism, using a Command class with execute and undo methods, and a history list, appears to be the first (1988) edition of Bertrand Meyer's book Object-oriented Software Construction,[5] section 12.2.

A sample UML class and sequence diagram for the Command design pattern. [ 3 ]
UML diagram of the command pattern