Question

For a newbie, how would you explain the difference between a controller command and a task command? What are the purposes of each? What might be an example of using the two types of commands?

Was it helpful?

Solution

See this documentation: http://pic.dhe.ibm.com/infocenter/wchelp/v6r0m0/index.jsp?topic=%2Fcom.ibm.commerce.developer.doc%2Fconcepts%2Fcsdcommand_framework.htm

Basically a task is a step in the larger process. A controller generally calls the tasks necessary to complete the entire process. If you have two processes (command controllers) that need the same task, they each call the task and no need to replicate that task's behavior in each controller.

Think of making a peanut butter sandwich and making a ham sandwich as your two command controllers. Getting a plate, putting bread on plate, and place top bread slice on sandwich would be shared. Getting ham, or getting PB would be tasks only used in the appropriate command controller.

OTHER TIPS

The Controller Command is the command that gets called upon a request, just like we have actions in struts and controller in Spring. A task is a step in the bigger process. Task commands are the commands that perform specific tasks for a controller command, like service classes in other frameworks. In order to complete the request, a controller command may invoke multiple task commands.

Other differences are - a. There is a url mapping for a controller command whereas Task commands don't have URLs mapped to them. b. Controller command gets invoked before the task command.

Controller Command

  • Holds the complete business logic for an action. Cannot be executed as an independent request but should be invoked from another command. Needs resource level access control policies to be defined and executed.

Ex - UserRegistrationAddCmd is used to Register a user.

Task Command

  • Holds a part of logic involved in an action i.e; to execute a specific task. Can be executed as an independent request. Does not need access control as this is executed from a controller command which already has the policies defined.

Ex- UpdateCredentialsCmd is invoked from UserRegistrationAddCmd to encrypt and update the credentials of the user.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top