当前位置:网站首页>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 .
边栏推荐
- Is it safe for Anxin securities to open an account online? Is the account opening fee charged
- 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"
- 解读数据安全治理能力评估框架2.0,第四批DSG评估征集中
- Analysis of abnormal frequency of minor GC in container environment
- What are cache penetration, cache breakdown, and cache avalanche
- Redis 的内存淘汰策略和过期删除策略的区别
- Is it safe to open an account online
- Go micro tutorial - Chapter 2 go micro V3 using gin and etcd
- 一文掌握数仓中auto analyze的使用
- Is it safe for Bank of China Securities to open an account online?
猜你喜欢
聊聊异步编程的 7 种实现方式
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
被PMP考试“折磨”出来的考试心得,值得你一览
PingCode 性能测试之负载测试实践
公司要上监控,Zabbix 和 Prometheus 怎么选?这么选准没错!
With an annual income of more than 8 million, he has five full-time jobs. He still has time to play games
雨量预警广播自动化数据平台BWII 型广播预警监测仪
detectron2安装方法
To sort out messy header files, I use include what you use
MVC模式和三层架构
随机推荐
Firewall basic transparent mode deployment and dual machine hot standby
容器环境minor gc异常频繁分析
设置窗体透明 隐藏任务栏 与全屏显示
2022PMP考试基本情况详情了解
curl 命令妙用
补能的争议路线:快充会走向大一统吗?
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
Leetcode list summary
CANN算子:利用迭代器高效实现Tensor数据切割分块处理
Learn more about the basic situation of 2022pmp examination
NFT流动性市场安全问题频发—NFT交易平台Quixotic被黑事件分析
Internet addiction changes brain structure: language function is affected, making people unable to speak neatly
长城证券开户安全吗 证券账户怎么开通
TP configuring multiple databases
【模板】【luogu P4630】Duathlon 铁人两项(圆方树)
手里10万元存款买什么理财产品收益最高?
The Block:USDD增长势头强劲
Vb无法访问数据库stocks
World Environment Day | Chow Tai Fook serves wholeheartedly to promote carbon reduction and environmental protection
The 18th IET AC / DC transmission International Conference (acdc2022) was successfully held online