Chain of Responsibility
Chain Responsibility Code
Command Pattern Code
Interpreter Pattern Code
Iterator Pattern Code
Mediator Pattern Code
Observer Pattern Code
State Pattern Code
The Command pattern encapsulates a request in an object, which enables you to store the command, pass the command to a method, and return the command like any other object.
The figure below illustrates the Command Pattern.
Invoker aggregates an abstract Command.
Command Pattern in Java
The following lists the benefits of using the Command Pattern:
Separates the object that invokes the operation from the one that knows how to perform it.
It's easy to add new commands, because you don't have to change existing classes.
When to Use:
You should use the Command pattern when:
You want to parameterize objects by an action to perform.
You specify, queue, and execute requests at different times.
You must support undo, logging, or transactions