aspose file tools*
The moose likes Struts and the fly likes Difference MVC2 vs MVC ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Difference MVC2 vs MVC ???" Watch "Difference MVC2 vs MVC ???" New topic
Author

Difference MVC2 vs MVC ???

rahul saxena
Greenhorn

Joined: Jun 10, 2003
Posts: 17
hi all,

how MVC2 is different from MVC??? what are the advantages in MVC2???.
Thanks in advance!!!

Rahul
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Read this part of "Designing Enterprise Applications with the J2EETM Platform, Second Edition".

In short,
MVC1 (Model 1) = JSP as "V" and "C", JavaBean as "M"
MVC2 (Model 2) = Servlet as "C", JSP as "V", JavaBean as "M"


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Lasse,

As MVC 1 mixes up View and Controller, it seems not a good idea for seperation of responsibility.

However, will there any systems that use MVC-2 is more suitable than MVC-1?

Nick


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Yes, that's exactly why MVC2 is the successor for MVC1.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
Oh...sorry, I typed the wrong pharse.

I wanna ask: are there any system that use MVC-1 will be better than MVC-2.

Nick
friso dejonge
Ranch Hand

Joined: Jul 11, 2002
Posts: 162
Hi Nick,

I think small systems will be profit from mvc1 since they do not need the overhead of a full scale mvc2 installation.
Again this could be debatable, however the larger the system the more you need architectural guidelines, or a consistent way of working. This is what mvc2 offers, see it as a best pratice (which is exactly what a design pattern is anyway)

regards,
friso


swimming certificate (A & B), shoelaces diploma, and some useless java ones.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
So, are there really any concrete example that systems are making use of MVC-1?

Nick
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724

I think small systems will be profit from mvc1 since they do not need the overhead of a full scale mvc2 installation


Did anybody measure this overhead?


SCJP<br />SCWCD <br />ICSD(286)<br />MCP 70-216
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
The overhead might not be great becos both Servlet and JSP are located at server side. Also, the overhead might just lie between the transfer of request from JSP to Servlet, becos both of them shall execute the same piece of logic, and both of them in fact will be compiled into Servlet.

Nick
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Generally speaking, the "overhead" of MVC2 over MVC1 is that of development effort, not of execution performance. More separation -> more source files -> more to maintain. Obviously the scale tips at some point and the advantage is on MVC2's side. In my experience, that point comes very early in the project size curve.
friso dejonge
Ranch Hand

Joined: Jul 11, 2002
Posts: 162
thanks lasse, that is what I meant to say. Yes there are real life applications that do not have mvc2 implementations. I made one with about 20 pages and no beans, just using the session. This works fine, only 20 jsp's Why indeed would I need to create the overhead of actionforms, xml config files, actions etc, (maybe tiles) if it can be done in 20 pages ?
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

only 20 jsp's Why indeed would I need to create the overhead of actionforms, xml config files, actions etc, (maybe tiles) if it can be done in 20 pages ?

I guess MVC model is not a binding (or equivalent) to Struts, I can have MVC model even in non-Web-based applications (like the SCJD assignment), or just a pure combination of Servlets and JSPs.

In addition, on the development effort, of course it might be easier for developing for single JSP to work out everything, but then it is hard to maintain and reuse if some functions should be common.

This argument seems just backing to the old days that, if I just have small applications, why I need to maintain so many OO classes? I could simply put in everything into 1 or 2 objects to make it works.

Nick
David Ulicny
Ranch Hand

Joined: Aug 04, 2004
Posts: 724
It is the same as you will not have EJB's in your application, why then use WebSphere if Tomcat will be enough?
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
It is the same as you will not have EJB's in your application

This might be true.

why then use WebSphere if Tomcat will be enough?

But I wonder any systems in production really use Tomcat. Since there is lack of technical on-call support, thus, I guess only small systems from small firms will use Tomcat in production.

Nick
friso dejonge
Ranch Hand

Joined: Jul 11, 2002
Posts: 162
In addition, on the development effort, of course it might be easier for developing for single JSP to work out everything, but then it is hard to maintain and reuse if some functions should be common.

This argument seems just backing to the old days that, if I just have small applications, why I need to maintain so many OO classes? I could simply put in everything into 1 or 2 objects to make it works.


Which is exactly why only small applications (be it webbased or not) will benefit. Which is exactly what Lasse and myself said. Which is exactly the question you asked.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Nicholas Cheung:
But I wonder any systems in production really use Tomcat. Since there is lack of technical on-call support, thus, I guess only small systems from small firms will use Tomcat in production.

Well, practically every single Java hosting provider out there is running Tomcat. That makes a lot of business
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

Which is exactly why only small applications (be it webbased or not) will benefit

That is to say, if your write small applications, even you use Java, you will use 1 single class or as small as possible classes for it?

However, even for small applications, I will try to have *reasonable* # of classes, just if the needed (seperation of the responsibility). And, I will still use MVC model even if I just got 20 pages of JSP. I will just follow a better practice to work with. Otherwise, all things mess up, as you can have a JSP page with 2000+ lines of codes to mess up everything!!!

Thus, we are NOT in the same point of view, and that's NOT what I was asking. And if you are not understand or answering what I was asking, please dont try to put down such statement *Which is exactly the question you asked*.

Nick
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

Well, practically every single Java hosting provider out there is running Tomcat. That makes a lot of business

Well, however, I have just worked with Tomcat in the testing environment, and I havent had any applications that eventally deployed on Tomcat.

Nick
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

There is no such thing as MVC1 or MVC2.

There IS a Model 1 and a Model 2 architecture. Model 1 is client-server. Model 2 IS MVC.

This is a very common mixup because the word Model is also what the M stands for in MVC.


A good workman is known by his tools.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
There is no such thing as MVC1 or MVC2

For the terms MVC1 and MVC2, we are actually refering to MVC model 1 and MVC model 2.


There IS a Model 1 and a Model 2 architecture. Model 1 is client-server. Model 2 IS MVC.

I think both models are MVC model, but just in MVC1, JSP acts as both controller and view, while in MVC2, JSP acts as view only, while Servlet acts as controller.


This is a very common mixup because the word Model is also what the M stands for in MVC.

Really having a mix? So far, I havent developed any systems that using JSP as the controller, as if we do so, then, a single JSP might contain thousands line of codes which is very difficult to maintain and reuse the code in future.

Nick
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Model 1 has nothing to do with the MVC pattern.
You can not say "JSP acts as both controller and view" because that defeats the purpose of the pattern (the purpose of the controller specifically).

You should have come across this question on your SCWCD. If you own the Deshmukh/Malavia book (SCWCD Exam Study Kit) you will find a terrific explanation there on pages 17 and 18.

Other resources for explanations:
http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssj-jspmvc.html
http://www.fawcette.com/javapro/2002_06/online/servlets_06_11_02/
http://struts.apache.org/
friso dejonge
Ranch Hand

Joined: Jul 11, 2002
Posts: 162
That is to say, if your write small applications, even you use Java, you will use 1 single class or as small as possible classes for it?

Well, however, I have just worked with Tomcat in the testing environment, and I havent had any applications that eventally deployed on Tomcat

Really having a mix? So far, I havent developed any systems that using JSP as the controller, as if we do so, then, a single JSP might contain thousands line of codes which is very difficult to maintain and reuse the code in future.

- I agree beforehand that this is a cut/paste from multiple posts, and i hope i havent taken them out of context too much -


Hi, nick,

I think you are mixing things up. Even in Model 1 you can have multiple classes, and therefore multiple jsp's. Using this model you still use multiple
objects, jsp's etc. You are just linking jsp's to each other (with a few helper classes)

On the tomcat thing, that must be the experience.

regards,
friso
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by Marc Peabody:
Model 1 has nothing to do with the MVC pattern.

Design Patterns are often used not in the exact form they're presented in literature, but in more or less modified forms.

I agree that it would be better to say "Model 1" and "Model 2" instead of "MVC1" and "MVC2". It would be less confusing. However, those terms are being used -- wrongly or not -- also in Sun's own documentation.
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Thanks for the link, Lasse.

The chapter says that it references JSP 0.91 and J2EE Blueprints but I could not find MVC1 or MVC2 in either of those documents. I was hoping to find a date somewhere in the Sun ONE Architecture Guide but found none.


This approach ["MVC1"] combines Controller and View functionality within a JSP page and therefore breaks the MVC paradigm.

This point is really more important than the terms used. This is what I mean that Model 1 has nothing to do with MVC. It doesn't fit the essence of the pattern.

It seems that associating Model 1 with MVC is more than just a bit off. It's like saying a duckbilled platypus is a bird except that it flies underwater, drinks its mother's milk, and has fur and therefore breaks the bird paradigm.

If anyone knows of more articles or documentation on this naming issue, please post cause I'd love to read them - more so now for a history lesson on the origins of when and who started saying which.
 
jQuery in Action, 2nd edition
 
subject: Difference MVC2 vs MVC ???