Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the actual difference between MVC and MVC Model2

just i want to know What is the actual difference between MVC and MVC Model2 in the development

like image 959
Ashvin Ranpariya Avatar asked Apr 28 '09 06:04

Ashvin Ranpariya


2 Answers

To illustrate the previous answers (and add explanation from this article):

MVC2 is an abuse of language referring actually to the JSP Model 2 architecture, as opposed to JSP Model 1:

The first Java technology for server-side web development was the servlet.
Writing applications with servlets was very similar to writing CGI applications in Perl in that all of the output had to be built up as Strings from within Java code.
This was very tedious and error-prone. It also made it very difficult for web designers with no Java experience to alter the look and feel of the pages generated by servlets.

alt text
(source: javaworld.com)

Then came JSP. JSPs, like Microsoft ASPs and like the popular scripting language PHP, treat everything as template text, but allow the insertion of Java code into tags called scriptlets and JSP expressions.
This allowed people to work on server-side applications just as they would with the other popular scripting languages but it had a couple of drawbacks.

  • There was no separation of concerns.
  • One script would hold database code, business logic, HTML markup and any javascript code needed for the final page rendering.
  • Code reuse was difficult as was automated testing.

This came to be known as "Model 1" JSP programming.

MVC or the Model View Controller pattern was a common technique for separating the various concerns in GUI code invented by Trygve Reenskaug, working on Smalltalk for Zerox.

At some point it became clear that this technique could be adapted to Java EE applications to achieve the same level of separation.
Doing so involves writing the Model layer as Beans or Plain Old Java Objects (POJOs), using servlets as the Controller, and then, when all the heavy lifting is done, forwarding to a JSP to format and markup the results.
Servlet/JSP applications written using and MVC architecture came to be known as Model 2 JSP programming.

alt text
(source: javaworld.com)

Because this pattern existed in a different form before being used in servlet/JSP applications, it was sometimes referred to as "MVC2". This name led to some confusion as it implied that there is an MVC1 for servlet applications, which there is not.
It is sufficient just to say MVC.

like image 132
VonC Avatar answered Oct 21 '22 11:10

VonC


An amusing historical note on the terms...

[I wish I could find the paper... (I just tried googling but no luck!)]

A while back, someone wrote a paper describing two MVC approaches for web applications. In it, he had two figures.

The captions were "model 1" and "model 2".

They weren't intended as actual names of patterns (more like "figure 1" and "figure 2"), but someone read it and wrote about it as though that were a pattern name...

(anyone have the ref?)

VonC describes the difference pretty well

like image 35
Scott Stanchfield Avatar answered Oct 21 '22 12:10

Scott Stanchfield