• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can we have more than one controller in MVC pattern?

 
Naina Si
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we have more than one controller in MVC pattern
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure! Depends on the needs of your system.

Nick
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Struts is an good example, you can have more than 1 ActionDispatcher.

Nick
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on what you mean by "controller".

There are basically two types of controllers: application and infrastructure. An application controller is any code that responds to a specific user request. Such controllers are used to implement the activity flow within use cases in your application. An infrastructure controller is any code that responds generically to user requests and perform functionality that spans multiple application user requests.

For example, in Struts the Action classes you create are application controllers. These are things like "add an item to my shopping cart," "search for a product in the catalog," "display my shopping cart," "log in," "log out," and so on.

The ActionServlet class is the infrastructure controller. That servlet performs generic operations, such as populating form beans, validating form beans, executing the app. controller (an Action object), and dispatching to the appropriate view based on the execute methods return value. [Well, technically the RequestProcessor class/subclass does this work, but the ActionServlet delegates that work to the RequestProcessor.]

So in Struts, any given user request is likely to through the infrastructure controller (ActionServlet) first, which then dispatches the request to the appropriate application controller which performs the actual functionality for that request.

HTH,
Bryan
[ October 20, 2004: Message edited by: Bryan Basham ]
 
Naina Si
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks much for the clear cut explanation.

When i say controller, i meant the servlet controlling the flow to different models.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thus, could (or should) we have a design that:

There is 1 single entrance point (FrontController) to the system (say Servlet X for login checking), while it will then dispatch the requests to corresponding Servlets, which acts as MVC?

Nick
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic