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.
Is the UNDO operation is a must one in Command Pattern or what?
Because in my application, I am calling the RequestHandler based on the RequestObject. The Request URL will be parsed and RequestHandler Object is created using Java Reflection API's. Then we are calling RequestHandler.execute (Request) method. But there is no undo operation is defined in my design. Why do we require undo operation in the Command design pattern?
Originally posted by Jeff Langr: The ability to undo operations (commands) demonstrates one of the benefits of using the command pattern. It is not required.
...and 'Undo' is itself a command anyway.
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Malli Raman
Ranch Hand
Joined: Nov 07, 2001
Posts: 312
posted
0
Originally posted by Jeff Langr: The ability to undo operations (commands) demonstrates one of the benefits of using the command pattern. It is not required.
Hi Jeff & David,
Thanks for quick reply.
Just for a clarification whether following case will be considered as a command pattern implementation:
1. User enters http:\\ viewCustomer.do 2. After parsing the URL in a controller servlet, calling the viewCustomerRH.execute(HttpRequest req, HttpResponse res) 3. Similarly for deleteCustomer.do calls deleteCustomerRH.execute(HttpRequest req, HttpResponse res) in that controller servlet. [that is based on user request, the url be parsed in the controller servlet and the corresponding requesthandler method is called, here I don't have undo operation(As it is meaningless in this case)].
Regards, M.S.Raman
David Hibbs
Ranch Hand
Joined: Dec 19, 2002
Posts: 374
posted
0
Originally posted by Malli Raman:
Hi Jeff & David,
Thanks for quick reply.
Just for a clarification whether following case will be considered as a command pattern implementation:
1. User enters http:\\ viewCustomer.do 2. After parsing the URL in a controller servlet, calling the viewCustomerRH.execute(HttpRequest req, HttpResponse res) 3. Similarly for deleteCustomer.do calls deleteCustomerRH.execute
I think you may be confused here between Command Pattern and the Chain of Command pattern. All the command pattern implies is that there is a single, specific command given which will be executed.
Consider the military. If your superior officer issues you a Command, you carry it out.
This question sounds more like a Chain of Command question.
I'm guessing--possibly incorrectly--that what you refer to as viewCustomerRH and deleteCustomerRH are members of your action. If so, then this is NOT a Command pattern and is instead an example of delegation.
If they are not members, and are perhaps actions themselves, then it could *possibly* be a chain of command, but not necessarily. It sounds more like a work-flow...
I think you could make the case for command. Based on the URL the container looks up a Java object that implements an execute() interface and executes it. The object encapsulates the processing that should happen for the URL. The interface and processing fit command. BTW: Where's the mapping from the name.do to fully.qualified.servlet.classname?
With Struts and many other "front controller" frameworks you go one step further by sending all requests through one object that does the look up and execute. I did that in my scratch-built Wiki and felt the things I executed were definitely commands. I even called the interface something Command.
In the long run, whether it is command or 80% command or a mix of command and chain of command doesn't matter a whole lot. You won't be graded on pattern purity. But it would be nice if you could say "It's like command, except this little thingie" to a new team member and they get what you mean in a fraction of the time it would take to describe the whole mess.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: UNDO operation is mandatory in Command Pattern?