This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
so can you tell me where exactly a Command Pattern is used . ( Can i think it this as an example consider a situation where there are a number of buttons like add , delete , update --- etc for every button there is a particuar method called .
Sorry for my english.
Joined: Jul 05, 2005
Command pattern decouples Invoker and Receiver. Invoker will only have dependency to Command interface, not concrete implementation.
It also able to support Undo/Redo. When execute a command we can keep it in a command stack, and after that we can undo/redo by getting a command from the stack and call undo/redo method.
1) Initial Program we have one sender and one receiver.
Receiver is Calculator:
Sender is the Client:
//Client want add function in Calculator, He raises add request through calculator object.
Calculator calc = new Calculator();
In the above scenario, Client(Sender) directly calls the Calculator(Receiver) through sending request.
In the command design pattern:
Third Person will enter here, who takes the command from client(Sender) and do work with receiver(Calculator).
Sender --> Thirdparty --> Receiver.
Here Thirdparty means Invoker.
a) ThirdParty decouples the Sender and Receiver.
In command desing pattern 4 roles are there:
Encapsulate a request as an object, thereby letting you parameterize clients with different requests, queue or log requests, and support undoable operations.
Encapsulate a request as an object means
Client wants add request:
In command design pattern, Receiver(Calculator) have functions/operations. For each/combination of operations we create speration commandHolder.