当前位置:网站首页>MVC mode and three-tier architecture
MVC mode and three-tier architecture
2022-07-04 17:33:00 【Grilled little fat sheep with charcoal...】
MVC Pattern and three-tier architecture
MVC Pattern
MVC(Model View Controller) Is a software design pattern in software engineering , It divides software systems into Model 、 Views and controllers Three basic parts . Using a business logic 、 data 、 The interface displays the separated method organization code , Gather business logic into a component , While improving and personalizing the interface and user interaction , No need to rewrite business logic .
MVC Is a layered development model , among :
- M:Model, business model , Deal with business , The core function of the application , Manage the data and values used in this module (bean,dao).
- C:Controller, controller , Processing requests , Call models and views , Respond to user input , Manage the interaction between users and views , It's the hub between the model and the view (servlet/service).
- V:View, View , Interface display , How the management model is displayed to users , It's the look and feel of the application (jsp/html).

controller (serlvlet) Used to receive requests sent by the browser , Controller call model (JavaBean) To get data , For example, query data from the database ; After the controller obtains the data, it is handed over to the view (JSP) Show the data . In the process , In fact, the controller only serves as a connecting link between the preceding and the following , It is only responsible for transit ( Command and dispatch ), Not responsible for specific business operations .
MVC advantage :
- Single responsibility , They don't influence each other . Each character does its own thing , Attend to each one's own duties .
- Conducive to division of labor and cooperation .
- It's good for component reuse
MVC shortcoming : Complicate the project architecture , High requirements for developers
Three layer architecture
Three layer architecture (3-tier architecture) Is to divide our project into three levels , Namely The presentation layer (User Interface layer)、 Business logic layer (Business Logic Layer)、 Data access layer (Data access layer).
The purpose of the hierarchy is to High cohesion and low coupling Thought . In software architecture design , Layered structure is the most common , And the most important structure .
- Data access layer : The database is CRUD Basic operation .
- Business logic layer : Encapsulate business logic , Basic functions in the composite data access layer , Form complex business logic functions . for example
Register business functions, We'll call it firstData access layerOfselectByName()Method to determine whether the user name exists , If it doesn't exist, call againData access layerOfinsert()Method to add data . - The presentation layer : Receiving request , Encapsulated data , Call the business logic layer , The response data .
And the whole process is , Browser send request , Expressional Servlet Receive the request and call the method of business logic layer for business logic processing , The business logic layer method calls the data access layer method to operate the data , Return to serlvet, then servlet Leave the data to JSP To display .
Each layer of the three-tier architecture has a unique package name :
- The presentation layer :
controllerperhapsweb - Business logic layer :
service - Data access layer :
daoperhapsmapper
We often hear SSM A framework is the encapsulation of different layers :
Advantages of three-tier architecture :
- Developers can focus on just one layer of the entire structure .
- High maintainability , High scalability .
- Can reduce layer to layer dependency .
- Conducive to standardization .
- It is conducive to the reuse of logic at all levels .
Disadvantages of three-tier architecture :
- It reduces the performance of the system . If you don't use a layered structure , Many businesses can visit the database directly , In order to obtain the corresponding data , Now it has to be done through the middle tier .
- Sometimes it leads to cascading changes , This change is especially reflected in the top-down direction . If you need to add a function in the presentation layer , In order to ensure that its design conforms to the layered structure , You may need to add code in the corresponding business logic layer and data access layer .
- Increased development costs .
MVC Connection with three-tier architecture

As shown in the figure above, the upper part is MVC Pattern , The lower part of the figure above is a three-tier architecture . MVC Pattern Medium C( controller ) and V( View ) Namely Three layer architecture The presentation layer in the , and MVC Pattern Medium M( Model ) Namely Three layer architecture Medium Business logic layer and Data access layer .
Can be MVC Pattern Understood as a big concept , and The three-tier architecture is right MVC The idea of pattern implementation architecture . Actually , Whether it's MVC Or three-tier architecture , It's all a norm , It's all running High cohesion , Low coupling The idea to design .
MVC Similarities and differences with the three-tier architecture
Difference
Three tier architecture is a typical way of program design , After establishing the project, the first thing to do is to design its architecture , The three-tier architecture is to layer the application , So as to reduce the coupling between various modules . and MVC Is a design pattern of program , That is, a mode that the application determines whether to adopt according to the requirements after establishing the architecture , It is a way to make program code organized 、 Logic 、 General code specification . Therefore, the difference between the two also appears , The three-tier architecture is a kind of architecture and MVC It's a design pattern ( Or a design idea ).
The hierarchical mode of three-tier architecture is a typical up-down relationship , The top depends on the bottom . but MVC As a mode of expression, there is no up-down relationship , It's a collaborative relationship . Even if MVC As an architectural pattern , It's not a hierarchical model .MVC It is basically meaningless to compare with the three-tier architecture , It's a technology that's used in different fields .
The same thing : MVC Although it is essentially different from the three-tier architecture , But in the goal achieved 、 The effect achieved is the same , Both are for application decoupling , Even if the application reaches ” High cohesion , Low coupling “ Purpose .
边栏推荐
- detectron2安装方法
- Cocoscreator event dispatch use
- 【华为HCIA持续更新】SDN与FVC
- 什么是低代码开发?
- What grade does Anxin securities belong to? Is it safe to open an account
- gatling 之性能测试
- [HCIA continuous update] overview of WLAN workflow
- To sort out messy header files, I use include what you use
- 码农版隐秘的角落:作为开发者最讨厌的5件
- How to choose one plus 10 pro and iPhone 13?
猜你喜欢

OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首

go-micro教程 — 第二章 go-micro v3 使用Gin、Etcd

What if Kaili can't input Chinese???

【HCIA持续更新】网络管理与运维

解读数据安全治理能力评估框架2.0,第四批DSG评估征集中

数学分析_笔记_第7章:多元函数的微分学

【HCIA持续更新】广域网技术

Analysis of abnormal frequency of minor GC in container environment

Rainfall warning broadcast automatic data platform bwii broadcast warning monitor

斑马识别成狗,AI犯错的原因被斯坦福找到了丨开源
随机推荐
VMware Tools和open-vm-tools的安装与使用:解决虚拟机不全屏和无法传输文件的问题
PingCode 性能测试之负载测试实践
How to choose one plus 10 pro and iPhone 13?
Is it safe for Bank of China Securities to open an account online?
一文掌握数仓中auto analyze的使用
Analysis of abnormal frequency of minor GC in container environment
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
长城证券安全不 证券开户
Display opencv drawn pictures on MFC picture control control
Vscode modification indentation failed, indent four spaces as soon as it is saved
New technology releases a small program UNIPRO to meet customers' mobile office scenarios
整理混乱的头文件,我用include what you use
Zebras are recognized as dogs, and the reason for AI's mistakes is found by Stanford
Web game engine
What are cache penetration, cache breakdown, and cache avalanche
【云原生】服务网格是什么“格”?
Implementation of super large-scale warehouse clusters in large commercial banks
ble HCI 流控机制
就在今天丨汇丰4位专家齐聚,共讨银行核心系统改造、迁移、重构难题
VSCode修改缩进不成功,一保存就缩进四个空格