当前位置:网站首页>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 layer
OfselectByName()
Method to determine whether the user name exists , If it doesn't exist, call againData access layer
Ofinsert()
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 :
controller
perhapsweb
- Business logic layer :
service
- Data access layer :
dao
perhapsmapper
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 .
边栏推荐
- 如何实现一个延时队列 ?
- 开发者,MySQL专栏完更,助你轻松从安装到入门进阶
- 手里10万元存款买什么理财产品收益最高?
- [template] [Luogu p4630] duathlon Triathlon (round square tree)
- 解决el-input输入框.number数字输入问题,去掉type=“number“后面箭头问题也可以用这种方法代替
- 你应该懂些CI/CD
- Hidden corners of coder Edition: five things that developers hate most
- 解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
- CANN算子:利用迭代器高效实现Tensor数据切割分块处理
- 51 single chip microcomputer temperature alarm based on WiFi control
猜你喜欢
S2b2b solution for lighting industry: efficiently enable the industrial supply chain and improve the economic benefits of enterprises
VSCode修改缩进不成功,一保存就缩进四个空格
【Go ~ 0到1 】 第六天 文件的读写与创建
To sort out messy header files, I use include what you use
整理混乱的头文件,我用include what you use
被PMP考试“折磨”出来的考试心得,值得你一览
Solve the El input input box For number number input problem, this method can also be used to replace the problem of removing the arrow after type= "number"
PingCode 性能测试之负载测试实践
wuzhicms代码审计
Electronic pet dog - what is the internal structure?
随机推荐
Electronic pet dog - what is the internal structure?
上网成瘾改变大脑结构:语言功能受影响,让人话都说不利索
DataKit——真正的统一可观测性 Agent
[Acwing] 58周赛 4490. 染色
离线、开源版的 Notion—— 笔记软件Anytype 综合评测
It's too convenient. You can complete the code release and approval by nailing it!
Image retrieval
Face_recognition人脸识别之考勤统计
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
【HCIA持续更新】WLAN工作流程概述
什么是低代码开发?
kaili不能输入中文怎么办???
What grade does Anxin securities belong to? Is it safe to open an account
The Block:USDD增长势头强劲
[unity ugui] scrollrect dynamically scales the grid size and automatically locates the middle grid
Internet addiction changes brain structure: language function is affected, making people unable to speak neatly
Wuzhicms code audit
OPPO小布推出预训练大模型OBERT,晋升KgCLUE榜首
PingCode 性能测试之负载测试实践
Analysis of abnormal frequency of minor GC in container environment