Post navigation

Command Pattern

Command Pattern

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.