File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Command pattern

 
nitinram agarwal
Ranch Hand
Posts: 90
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 661
Eclipse IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic