File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Spring and the fly likes Why should we separate model from controller in MVC Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "Why should we separate model from controller in MVC" Watch "Why should we separate model from controller in MVC" New topic
Author

Why should we separate model from controller in MVC

Ram ank
Greenhorn

Joined: Apr 28, 2011
Posts: 10
I know this is simple question.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16624

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Ram ank
Greenhorn

Joined: Apr 28, 2011
Posts: 10
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
Sheriff

Joined: Feb 05, 2001
Posts: 16624

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
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50691

Of what possible use is servlets in the model?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
IntelliJ Java IDE
 
subject: Why should we separate model from controller in MVC
 
developer file tools