• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can we have more than one controller in MVC pattern?

 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we have more than one controller in MVC pattern
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Struts is an good example, you can have more than 1 ActionDispatcher.

Nick
 
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Get me the mayor's office! I need to tell him about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic