Why one should follow MVC along with Cohesiveness

Thursday, April 28, 2011 Labels: , , ,
In web development, MVC (Model View Controller) design pattern is considered most basic infrastructure for a web project. It does the separation of UI (user interface / presentation layer) from Business intelligence (data processing) and flow of control between User Interfaces and data processing layer. This way one can focus on only one layer and extends/customize it to its limit.

The web projects following this approach are easy to maintain, debug, enhance and test and they are quite extendable. Not only this, one can use different technology for each layer.

The popular MVC framework for Java developers are

  1. Spring MVC
  2. Struts
  3. Stripes
I recommend at least java developers to follow one of MVC framework. It would be highly beneficial for them.
I recently went through a project which was built using IBatis, Strips, JDBC and JQuery. As it was developed by an offshore team hired by a company and running under its CTO. It had designed all the design for this project

 I found following drawbacks in their project

1. Not using MVC strictly

2. Naming Convention 

3. Putting all the code (data processing, JQuery, Presentation layout in mostly in per JSP bases. Because of that code was redundant.

4. Project was also following Strips layout structure as Tiles do in struts, but its use was very limited.

5. Debugging code was awful because mostly code was writing in JSPs, sometimes control moves directly from one JSP to other to get the required results and sometimes some service come in to play.

In short, it was all mess. I wrote above paragraph to identify the areas where one should focus and try to avoid them in any case.

Enough talk on MVC, what if one doesn't have this pleasure, still one can separate components/modules in different files/layers.

Yes, they’ll have to get the same privileges from themselves.

So they all have to do is to get these privileges.


Well I tell you. It might help you in your future projects.

Four functional components
1. Design a web-site with four functional components (Header, Menu, Footer, and Body) into different files (Presentation Layer)

Common file for CSS and JavaScript
2. Have common/separate file/files for CSS and JavaScript/Ajax (never put them in html)

Service layer
3. Data Processing/Business logic, try to put them in to separate file too and get the results from there. These files (weather you are using PHP, JSP) will behave like a service layer (where you business logic resides)

SQL Query File
4. Use common file for SQL queries to be used in your service classes.

Database Connection
5. Put database connection pooling code in one file and use it as you needed in your service.

If you follow above five practices, you will achieve cohesiveness and MVC like behavior and it will help you on the longer run.

This is all from me for now. Give your comment and feedback and your thoughts on it.


Post a Comment

Waqas Sadiq © 2014