• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alternate MVC design?

 
Junaid Kirkire
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to build a Java Web application. I want to use MVC but I don't want to make a JSP page and a Plain Old Java class (which will be referenced in the servlet) for every functionality that I will be having in my app.

In other words, I don't want something like-

Function 1 -->Servlet 1-POJO 1-JSP 1
Function 2 -->Servlet 2-POJO 2-JSP 2

etc.

Can anyone suggest a better design?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your example is too vague to be of any use in figuring out what you're trying to say.

But in any case, the real answer is that you need to create as many elements as makes sense. If you're going to want to take short cuts and skip steps that are necessary you might as well just throw all pretense of following the pattern out the window.

Perhaps you need to expand on exactly what you're driving at?
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Function 1 -->Servlet 1-POJO 1-JSP 1
Function 2 -->Servlet 2-POJO 2-JSP 2


This doesn't resemble any MVC implementation that I have created. My MVC implementations are something like:

JSP 1 ---------> Controller ---------> Business Object Domain X
JSP 2 ---------> Controller ---------> Business Object Domain X
JSP 3 ---------> Controller ---------> Business Object Domain X
JSP 4 ---------> Controller ---------> Business Object Domain X

JSP 5 ---------> Controller ---------> Business Object Domain Y
JSP 6 ---------> Controller ---------> Business Object Domain Y
JSP 7 ---------> Controller ---------> Business Object Domain Y
JSP 8 ---------> Controller ---------> Business Object Domain Y


A single Controller is the mediator between Presentation GUI and Business Model.

The Struts Framework will help you implement this type of Controller. All of the Struts Action objects are part of the Controller and you easily configure these objects with a simple XML-based configuration file(s).


 
Junaid Kirkire
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies!

What I am trying to say is that for every single Java class (or rather the Business logic for a particular function), we use only one servlet. That servlet references to only that Java element and then passes it on the JSP. I was thinking if we can ever use a single Servlet which can be associated with multiple Business logic elements simultaneously and render the corresponding JSPs.


Thanks again!
PS:- I am a student and not very experienced as you people are. Can you help me master this aspect please?!
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I am trying to say is that for every single Java class (or rather the Business logic for a particular function), we use only one servlet.


When you are saying "we use only one servlet", this is only your opinion or a rudimentary MVC implementation that you are aware of. In practice, a Controller is made up of many objects, a Java Servlet object is only one of many.

If you really attempted to code everything in a single Servlet class, it would be a nightmare for anything but a few (less than 5) operations. The Model-View-Controller design pattern is intended for larger applications with hundreds of operations, for example.

As mentioned, the Struts Framework provides the "skeleton" of the Controller components. If you study Struts and learn how to design with it, then you will understand how a Controller is created.

It takes about two years to adequately learn object-oriented design if you are dedicated and read and practice consistently. To considered yourself a "master", you most likely will need five to seven years. Learning the differences between software programming and software design is a good step forward. Good luck!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic