A Command Pattern says that "encapsulate a request under an object as a command and pass it to invoker object. Invoker object looks for the appropriate object which can handle this command and pass the command to the corresponding object and that object executes the command".
It is also known as Action or Transaction.
Advantage of command pattern
Usage of command pattern:
It is used:
Example of command pattern
Let's understand the example of adapter design pattern by the above UML diagram.
UML for command pattern:
These are the following participants of the Command Design pattern:
Implementation of above UML:
Create a ActionListernerCommand interface that will act as a Command.
Create a Document class that will act as a Receiver.
Create a ActionOpen class that will act as an ConcreteCommand.
Create a ActionSave class that will act as an ConcreteCommand.
Create a MenuOptions class that will act as an Invoker.
Create a CommanPatternClient class that will act as a Client.