File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web app design confusion

 
Dhaval J. Patel
Ranch Hand
Posts: 90
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I am facing a complicated design issue. I would like to have your opinions on what approach should I take.

I am dealing with the code written by previous programmers. It is a small booking web application.

The web application has a single servlet with a big if-else block (with around 80 conditions) where it compares one of the parameter and decides where to redirect the request and what processing to do. The same servlet has around 55 functions which are being called by different parts of the if-else block. These functions connect directly to the data access objects. There are a few javabeans which are used by the functions and the data access objects. The data access objects contain business logic and the data access code. Everything tangled together.

My boss wants me to add more functions to this web app. I tried adding stuff to it but it breaks other things. So I started cleaning up and cleaned up the data access objects and removed business logic from them. In short added an extra layer before the data access objects. But I havent integrated it with the main application yet. And now I am trying to remove all the code from the servlet and form a business layer with those functions in different classes.

But the servlet still has that bigg if-else block. Should I make one servlet for each condition or group them based on commonality. I was wondering how much code should every servlet have? I need to get request parameters put them into session variables, call appropriate business methods and redirect to appropriate page. Even that is a lot of code. I was wondering how much code should an ideal servlet have and how to ideally decide on the number of servlets required ?

And this system is running right now. So I cannot even do an overhaul and implement the web app with a framework. It has to be gradual and I need to add functions to the web app too. It is a nightmare. Please give me some suggestions on how to approach this situation. I am a newbie and totally new to such situations.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each servlet should have one and only one purpose. The second that you have mutually exclusive if-else's or switch labels, your code is an anti-patterm.
 
Dhaval J. Patel
Ranch Hand
Posts: 90
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Each servlet should have one and only one purpose.


So, should I make a servlet for each condition. Wouldnt that make a large number of servlets ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. But the number of servlets is an irrelevant metric. The clarity of the code is what matters.

If you want to keep the number of servlets down, while maintaining good separation of functionality, implement the Front Controller pattern. Read this article for more info.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Bear said, this seems like a good candidate for the front controller pattern.
 
Dhaval J. Patel
Ranch Hand
Posts: 90
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your answers. I will try the front controller pattern . I'll post if I run into problems.

Thanks
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic