Friday, January 31, 2014

Behaviroal DP : Command Design Pattern



Command design pattern is used to encapsulate a request as an object and pass to an invoker, wherein the invoker does not knows how to service the request but uses the encapsulated command to perform an action.
A request is wrapped under a object as command and passed 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. This scenario we can call it as Command Pattern.
The client invokes a particular module using a command. The client passes a request, this request gets propagated as a command. The command request maps to particular modules. According to the command, a module is invoked.
Command design pattern related terms 
I)             Command is an interface with execute method. It is the core of contract.
II)           A client creates an instance of a command implementation and associates it with a receiver.
III)         An invoker instructs the command to perform an action.
IV)          A Command implementation’s instance creates a binding between the receiver and an action.
V)           Receiver is the object that knows the actual steps to perform the action.

No comments: