• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Why should we separate model from controller in MVC

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know this is simple question.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually the question is missing too much information for anyone to actually answer.

In general the Controller passes the model data to the view and gets the model from the view. The model is the model, it is your domain objects.

But when you say MVC, you don't say Spring MVC, or Swing MVC, or Struts, so it is too vague to give specific examples. Which would take too long anyway.

Mark
 
Ram ank
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my question is cant we integrate controller and model to be in same module
i.e use same technology like servlets for both.

lets say it is spring MVC
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ram ank wrote:my question is cant we integrate controller and model to be in same module
i.e use same technology like servlets for both.

lets say it is spring MVC



I actually missed that the question started with "why"

Why do we separate anything in Java, we can create just one class with one method and write all our code in that one method. But it is not good OO design, it will cost way too much to maintain that type of code. We separate concerns, so Model is a concern about holding the data of the application. Where the concern for a Controller is passing those data between the back end, say database, and the front end UI. Any coupling between them makes code more brittle and tough to enhance and maintain.

Mark
 
Sheriff
Posts: 67693
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of what possible use is servlets in the model?
 
reply
    Bookmark Topic Watch Topic
  • New Topic