Wednesday, 16 June 2010

mvc design pattern

MVC1 & MVC2 Design Patterns:

In order to develop web applications in easily manner & to reduce the complexity in architectural design and to increase flexibility and maintainablility of code we require some standard appraoach.
That’s why we use MVC design pattern in our applications. They are 2 types of MVC design patterns. They are: MVC1 AND MVC2.

In MVC1, M Stands for Model, V stands for view and c stands for Controller.
In general we use AWT, SWINGS, HTML, JSP, Velocity, Free Marker technologies to develop View part. To prepare Model part we use technologies like JDBC, Hibernate and EJB ETC., and to prepare Controller part we use technologies like Servlets, JSP, EJB etc.

MVC1 Model:
In MVC1  model, we will use a JSP component as controller and as view part.
In MVC1 , WE will use a JSP component to pick up all the requests came from clients, So that it called as JSP front.
In MVC1, we will use a JSP component to control the entire web application, So that it is called as Page-Centric Architecture.
DrawBacks:
1.       In MVC1 , we will use JSP COMPONENT to control the web application and to generate response. So that there is no clear cut separation between the components which are used for controlling and which are used for presentation.
2.       MVC1 model, we will use a JSP COMPONENT to control the entire web application but the existed JSP components may not be sufficient, still there may be a requirement to provide java code inside the JSP pages, which is against to JSP principles.
Due to these reasons we should go for an alternative for designing web applications i.e: MVC2 Model.  






MVC 2 MODEL:




  • In MVC2, we should use a Servlets as controller, set of  JSP PAGES as View part and JDBC Hibernate and EJB ETC OR Java Beans for Model part.
  • In MVC2, we will use a Servlets to trap all the requests came from clients, So that it called as Servlets Front.
  • In MVC2, we will use a Servlets to control the entire web application, So that it is called as Servlet-Centric Architecture.
Advantages:

  • In MVC2 , there is a clear cut separation between the components which we are used for controlling and which we are used for presentation.
  • MVC2 model will provide loosely coupled design in 2 -Tier architecture for web applications.

Example program for MVC2 Architecture or MVC2 design pattern

Note: Struts is framework, which was designed on the basis of MVC2 or simply MVC architecture only
MVC Rules and Regulations:

 to design any web applications on the basis of MVC Architecture or model we should follow the following rules and regulations.


  • In MVC based web applications we should not misuse the components i.e we should not use servlets to prepare view part and we should not use JSP components for controller part.
  • In MVC based we applications web applications, we should not access view part and model part directly.
  • In MVC based web applications controller and view should not interact with the database directly, they should interact with the data base through model part only.
  • In MVC architecture, controller may interact with model part for the sake of setting the data only not for the sake of the getting the data and view part will interact with model part for the sake of getting the data only not for the sake of the setting the data.
  • There is no limitation on the number of JSP pages utilization in view part but all the JSP pages should be java codeless
  • In MVC based web applications, we should not provide page-to-page navigation, we should provide page-controller-page navigation
  • we should use only one servlets as controller but we may use many more number of JSP pages as view part.

No comments:

Post a Comment