Command Design Pattern: The Command pattern is known as a behavioral pattern and is used to represent and encapsulate all the information required to call a method at a later time. This information includes the method name, the object that owns the method and values for the method parameters. Command pattern allows the requester of a particular action to be decoupled from the object that performs the action.
The Command Pattern is useful when we need to do the following task:
- A history of actions is needed
- You need callback functionality, like listeners in java
- Calls or Requests need to be handled at different times or in different orders
- The invoker should be decoupled from the object handling the invocation.
Lets take an example, Suppose we have an electric engine and we want to start and stop this engine on press or click of a button. We will use command patter to do this...