Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on MVC object creation

 
Barry Brashear
Ranch Hand
Posts: 303
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question on how the objects in an MVC pattern are created. Does another controller open all three - model, controller and views. Or, does
another controller open your controller, then your controller open the model and views. I'm thinking in terms of a large application that has many
mvcs.

Thanks.
 
Suman Mummaneni
Ranch Hand
Posts: 92
Google App Engine Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not think you can have many mvcs in one application. The application as a whole must follow the MVC principle.
 
Sarath PS
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think we can have multiple front controllers in a single web application.
 
Deepak Shankar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe We can have multiple controller instances in an application. For example, in business deligate pattern, we can define the same controller class by making the entry in web.xml(thereby a new instances for every business deligate will be created by the server).

<servlet>
<servlet-name>Delegate1</servlet-name>
<display-name>Delegate1</display-name>
<servlet-class>FrontController</servlet-class>
</servlet>
<servlet>
<servlet-name>Delegate2</servlet-name>
<display-name>Delegate2</display-name>
<servlet-class>FrontController</servlet-class>
</servlet>

Please correct me if I am wrong.
 
Deepak Shankar
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer Barry's question,
There is no specific rule that controller should create model and model should create a view etc. It is based on the framework.

If you take web applications, the controller "create" model instances and "invoke" view instances. In this case I have said "invoke" because the control is forwarded to the web container for creating the view instance. What the controller can do is just say response.forward() or response.redirect().

And generally we do not instantiate one controller from another controller.

Hope this helps.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic