aspose file tools*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Command Pattern - A Command for each Action 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 - A Command for each Action" Watch "Command Pattern - A Command for each Action" New topic
Author

Command Pattern - A Command for each Action

krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
Hi,
Are we going to have a specific Command for each Receiver(Action).


have a great day,
krishna prasad
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1823
    
    7

It depends. A Command could execute one of the Receiver's actions, but it could just as easily execute multiple actions depending, for instance, on the granularity of the actions.
A Command doesn't have to be specific to one concrete Receiver implementation, either.


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
Jelle Klap wrote:A Command doesn't have to be specific to one concrete Receiver implementation, either.


You mean that there can exist an implementation of a Command which has reference NOT to one concrete Receiver implementation but to it's interface. By progamming to an interface we can decouple Command and Receiver and a chance to call multiple Receiver implementations.
But on the other hand, the Reveiver implementations needn't be similar at all, they can be completely two different objects with different behaviors. In this case we cannot program to an interface and need to have two different Command implementations.
Am I right here?
Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1823
    
    7

Yep
krishna prasad gunasekaran
Ranch Hand

Joined: Jul 25, 2006
Posts: 158
Well thanks, but i have another one for you..
Struts say they use Command Pattern calling Action's execute() method. But i couldn't come around the explanation that a very basic simple use of inheritance and polymorphism can be called a pattern instead of a programming idiom. I mean, all request processor does is action.execute(), which by the way, just uses an interface reference to call the method. This is so very basic programming technique. can this be called Command Pattern.
Command Pattern, as far as i have understood, achieves complete decoupling of Invoker and Receiver. Meaning, the Invoker can invoke any Object, not just implementations of Action. All it care is to call Comamnd's execute(), which does the rest. But in struts this isn't the case, i guess.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Command Pattern - A Command for each Action