File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes OO, Patterns, UML and Refactoring and the fly likes Command pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Command pattern" Watch "Command pattern" New topic
Author

Command pattern

nitinram agarwal
Ranch Hand

Joined: Jan 29, 2009
Posts: 83
Hi,
I have a very basic question about the command pattern. Supose, I have an interface like



and some class implementing the interface Task





Can I say that the above code implements the command pattern?

Arun Kumarr
Ranch Hand

Joined: May 16, 2005
Posts: 513

Try answering these questions:

1. I want to undo the task which I just executed. How will you do it?
2. Is your main program the executor of the commands. Don't you want to have some designated class to play around with the commands?
3. Doesn't your commands belong to a specific entity. Like I want the laptop to have multiple commands. Pressing a button command, pressing the power button, opening the CD tray, plugging in the power cable etc.,
4. Finally your commands work on something, like the commands I mentioned above work on the laptop. What does your commands work on?

Also do read about 'states' in commands and there are lot of internet articles to clearly explain Command pattern.
Now to answer your question, it's just polymorphism (virtual method invocation).


If you are not laughing at yourself, then you just didn't get the joke.
 
Don't get me started about those stupid light bulbs.
 
subject: Command pattern