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
Joined: Jul 25, 2006
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?
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.
subject: Command Pattern - A Command for each Action