【WEEK1】【 DAY1】 MVC related history and concepts【English Version】

2024.2.26 Monday

1. What is MVC

  1. MVC stands for Model, View, and Controller, which is a software design paradigm.
  2. It is a method for organizing code by separating business logic, data, and presentation. The main purpose of MVC is to reduce the bidirectional coupling between views and business logic.
  3. MVC is not a design pattern, but an architectural pattern. Of course, there are differences among different MVCs.
  • Model: It is the data model, providing the data to be presented. Therefore, it includes data and behavior, which can be considered as a domain model or a JavaBean component (including data and behavior). However, now they are generally separated into Value Object (data Dao) and Service Layer (behavior Service). In other words, the model provides functions such as model data query and model data status update, including data and business.
  • View: Responsible for presenting the model, usually the user interface that we see, the things that customers want to see.
  • Controller: Receives user requests, delegates the request to the model for processing (state change), and after processing, returns the model data back to the view for presentation. That is to say, the controller acts as a dispatcher.
  • The most typical MVC pattern is the JSP + servlet + JavaBean model.

2. The Model1 Era

  1. In the early days of web development, Model1 was commonly used.
  2. In Model1, there are mainly two layers: the view layer and the model layer.
  3. Advantages of Model1: Simple architecture, more suitable for small project development.
  4. Disadvantages of Model1: JSP has non-single responsibilities, overburdened, and not easy to maintain.

3. The Model2 Era

Model2 divides a project into three parts: view, control, and model.

  1. User sends a request.
  2. The Servlet receives the request data and calls the corresponding business logic method.
  3. After the business is processed, the updated data is returned to the servlet.
  4. The servlet redirects to JSP, and JSP renders the page.
  5. The updated page is responded to the frontend.

4. Responsibility Analysis

  1. Controller:
  • Retrieve form data.
  • Invoke business logic.
  • Redirect to a specified page.
  1. Model:
  • Business logic.
  • Maintaining the state of data.
  1. View:
  • Displaying the page.
  1. Advantages of Model2: Model2 not only improves the code reusability and project scalability but also significantly reduces the project maintenance costs. The implementation of the Model1 pattern is relatively simple, suitable for rapid development of small-scale projects. In Model1, the JSP page takes on both the roles of View and Controller, mixing control logic and presentation logic together, resulting in very low code reusability and increasing the difficulty of application scalability and maintenance. Model2 eliminates the disadvantages of Model1.
  • 24
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值