Model 1 and Model 2 Architecture

Model 1 and Model 2 (MVC) Architecture

In this article, I am going to discuss Model 1 and Model 2 (MVC) Architecture. Please read our previous article where we give a brief introduction to Java Struts Framework. At the end of this article, you will understand the following pointers in detail.

  1. Model 1 Architecture
  2. Advantage of Model 1 Architecture
  3. The disadvantage of Model 1 Architecture
  4. Model 2 (MVC) Architecture
  5. Advantage of Model 2 (MVC) Architecture
  6. The disadvantage of Model 2 (MVC) Architecture
  7. The solution of Model 2 Architecture: Configurable MVC Components
Model 1 Architecture

To build up web applications Servlet and JSP are the two advanced main technologies.

Servlet is considered better than CGI. Servlet technology doesn’t create processes, rather it creates threads to handle requests (or string to deal with solicitation). The advantage of making a thread over process is that it saves memory consumption. Thus, numerous consequent solicitations can be effectively dealt with by servlet.

The problem with Servlet Technology is that the recompilation always takes place whenever any modification occurs in the design of code. It never provides a separation of concern. Presentation and Business logic are blended up.

JSP becomes the solution to all problems of Servlet. It provides a much better partition of concern; it becomes easy to isolate Presentation from Business logic. There is no need for redeployment if JSP is modified. JSP works as a support in developing web applications using JavaBean, custom labels, and JSTL to separate Business logic from our JSP, as a result, the debugging and testing becomes easy to do.

Model 1 and Model 2 (MVC) Architecture

Here, is the brief description of the flow of model 1 Architecture from the above diagram

  1. The request for the JSP page is sent by Browser.
  2. JSP accesses Java Bean and invokes business logic
  3. Database connect by JavaBean and data cannot be lost
  4. JSP generated response is sent to the browser
Advantages of Model 1 Architecture

The easy and quick development of web applications.

Disadvantages of Model 1 Architecture
  1. Navigation control is decentralized: only because of each JSP page that is only responsible for managing application state and confirming authentication and security.
  2. Time-consuming: To create custom labels in JSP much more effort is needed. So we are not able to use scriptlet tags.
  3. Hard to extend: It is used in smaller, simple task applications.
Model 2 (MVC) Architecture

MVC is the most used software design pattern in the app and web development. The design pattern consists of –

  1. Model
  2. View
  3. Controller

Model 2 (MVC) Architecture

Model: stores & manages data
  1. It consists of the system’s business logic.
  2. It contains all the data of the application.
  3. It represents the state of the application.
  4. It consists of those classes that have a connection to the database.
  5. The controller makes a connection with the model, fetches the data, and sends it to the view layer.
  6. The model connects with the database and stores the data into a database that is connected to it.
View: Graphical User Interface
  1. It consists of HTML, JSP, etc. into it.
  2. It represents the UI of the application.
  3. It is used to show the data that is being fetched from the controller, in turn, it fetches data from model layer classes.
  4. This view layer shows the data on the UI of the application.
Controller: Brains of the application
  1. The controller connects the model and view.
  2. The controller converts inputs from view to fulfill the demand to retrieve/update data in the model.
  3. The controller receives input from view and uses logic to convert the input to a demand for the model that grabs the data and the controller passes data to the view from the model back for the user for better display.
Advantages of Model 2 (MVC) Architecture
  1. The development of the application becomes fast.
  2. Multiple developers’ collaboration is easier.
  3. Easier to Update the application.
  4. As multiple levels are written properly in the application, thus debugging is easier.
Disadvantages of Model 2 (MVC) Architecture
  1. Understanding of the MVC architecture is difficult.
  2. Must have strict rules on methods.
The solution of Model 2 Architecture: Configurable Components
  1. The declarative approach is used to define view components, request mapping, etc.
  2. Configurable MVC support can be easily provided by the Struts Framework.
  3. All the action classes and view components in Struts 2 are defined in the struts.xml file.

In the next article, I am going to discuss Java Struts 2 Components in detail. Here, in this article, I try to explain Model 1 and Model 2 (MVC) Architecture and I hope you enjoy this Model 1 and Model 2 (MVC) Architecture article.

Leave a Reply

Your email address will not be published. Required fields are marked *