In Command pattern objects used to represent and encapsulate information that is needed to call operation at later time. This information includes operation name and object that owns method and values for method parameters.
When command pattern used three terms always will be associated with it i.e. client, invoker and receiver. Here client creates new command object and provides all information that is required to call method at later time. Invoker decides when method should be called. Lastly receiver is instance of class that contains actual method code.
In this design pattern command objects makes us easier to build general components that need to delegate, sequence or execute operation calls at time of their choice without knowing anything about who is the owner of method or what are method parameters.
- The Command interface
- The Invoker class
- The Receiver class
- The Command for turning on the light – ConcreteCommand #1
- The Command for turning on the light – ConcreteCommand #2
- The test class or client
- That’s it. Below is list of all design patterns link:
- Chain of Responsibility
- Template Method