当前位置:网站首页>Take you to master the three-tier architecture (recommended Collection)
Take you to master the three-tier architecture (recommended Collection)
2022-07-07 13:53:00 【Xiao Kai, who loves fishing】
Preface
Please pay attention to the following issues when reading this article :
1. What is a three-tier architecture ?
2. Why use a three-tier architecture ?
3. What is the difference between the three layers and the two layers used in the past ? What are its advantages ?
4. How to learn three-tier architecture well ? How to apply the three-tier architecture ?
One 、 What is a three-tier architecture
The three-tier architecture is to conform to “ High cohesion , Low coupling ” thought , Divide each function module into presentation layer (UI)、 Business logic
Series layer (BLL) and Data access layer (DAL) Three layer architecture , Each layer uses interface to access each other , And through the implementation of the object model
Body class (Model) As the carrier of data transmission , The entity classes of different object models generally correspond to different tables of the database , Entity
The attribute of the class is consistent with the field name of the database table .
Function division table of each module :
UI( The presentation layer ): | It mainly refers to the interface interacting with users . It is used to receive data input by users and display data needed by users after processing . |
BLL:( Business logic layer ): | UI Layer and the DAL The bridge between layers . Implement business logic . The business logic specifically includes : verification 、 Calculation 、 Business rules and so on . |
DAL:( Data access layer ): | Dealing with databases . The main purpose is to increase data 、 Delete 、 Change 、 check . Submit the data stored in the database to the business layer , At the same time, the data processed by the business layer is saved to the database .( Of course, these operations are based on UI Layer of . The user's needs are reflected in the interface (UI),UI Reflect to BLL,BLL Reaction to DAL,DAL Data manipulation , Step back after operation , Until the user needs data feedback to the user ) |
Three tier architecture operation flow chart :
How to connect the functional modules in the three-tier architecture ?
I want to mention Entity( Physical layer ): It doesn't belong to any of the three layers , But it is an essential layer . For a lot of data , Using variables as parameters is a little complicated , Because there are too many parameters , Easy to confuse . such as : I want to pass the employee information to the lower level , The information includes : Employee number 、 full name 、 Age 、 Gender 、 Wages ....... Using variables as parameters , Then there will be many parameters in our method , Most likely when used , Confuse parameter matching . Now , If you use entities as parameters , It will be very convenient , Don't consider the problem of parameter matching , You can use which attribute in the entity directly , Very convenient . This also improves efficiency .
Entity Role in three-tier architecture :
1. Implement the in object-oriented thinking " encapsulation "; |
2. Through the third floor , Transfer data between the three layers ;( notes : To be exact, the entity layer runs through the three layers , To connect the three layers ) |
3. For beginners , It can be understood in this way : Each data table corresponds to an entity , That is, the fields in each data table correspond to the attributes in the entity ( notes : Of course , In fact, it's not . Why? ? 1>) Maybe the entity we need does not exist in the entity corresponding to the data table 2>) We can put all fields in all data tables in one entity ) |
4. Each layer (UI—>BLL—>DAL) Data transfer between ( A one-way ) Is passed by variables or entities as parameters , In this way, the connection between the three layers is constructed , Completed the implementation of the function . |
( Add :3. in Why can we temporarily understand that each data table corresponds to an entity ??
The purpose of our system , Is to provide services for users , Users don't care how your system background works , Users only care about whether the software is easy to use , Whether the interface is in line with your own mind . The user interface is easy to add 、 Delete 、 Change 、 check , Then there should be corresponding additions in the database 、 Delete 、 Change 、 check , The specific operation object of adding, deleting, modifying and querying is the data in the database , To put it bluntly, the fields in the table . therefore , Treat each data table as an entity class , The attributes encapsulated by the entity class correspond to the fields in the table , In this case , When the entity runs through three layers , You can add, delete, modify and query data )
Between the three layers and the entity layer Dependency relationship :
Two 、 Why use a three-tier architecture
The purpose of the three-tier architecture is to “ High cohesion , Low coupling ”. A clearer division of developers , Focus more on the analysis of the core business logic of the application system 、 Design and development , Speed up the project , Improved development efficiency , It is conducive to the updating and maintenance of the project .
3、 ... and 、 The difference between three floors and two floors
Two layers of :
( When any place changes , Need to redevelop the whole system ." Multi-storey " On the first floor , Unclear division of labor and high coupling —— Difficult to adapt to changes in demand , Low maintainability 、 Low scalability )
Three layers :
( At what level does the change take place , Just change the layer , There is no need to change the entire system . A clear hierarchy , A clear division of responsibilities , Low coupling between each layer —— Improved efficiency , Adapt to changing needs , High maintainability , High scalability )
The advantages of three-tier architecture :
1. The structure is clear 、 Low coupling |
2. High maintainability , High scalability |
3. It is conducive to synchronous development tasks , Easy to adapt to changing needs |
Disadvantages of three-tier architecture :
1. It reduces the performance of the system . This is self-evident . 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 . |
2. 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 |
3. Increased code , Increased workload |
边栏推荐
- Introduction and basic use of stored procedures
- 566. Reshaping the matrix
- 3D Detection: 3D Box和点云 快速可视化
- PHP中用下划线开头的变量含义
- mysql 局域网内访问不到的问题
- Leecode3. Longest substring without repeated characters
- Getting started with MySQL
- Dry goods | summarize the linkage use of those vulnerability tools
- .net core 关于redis的pipeline以及事务
- toRaw和markRaw
猜你喜欢
TPG x AIDU | AI leading talent recruitment plan in progress!
室內ROS機器人導航調試記錄(膨脹半徑的選取經驗)
2022-7-6 Leetcode 977. Square of ordered array
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
Flink | 多流转换
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
Redis can only cache? Too out!
Redis只能做缓存?太out了!
Show the mathematical formula in El table
交付效率提升52倍,运营效率提升10倍,看《金融云原生技术实践案例汇编》(附下载)
随机推荐
内存溢出和内存泄漏的区别
"New red flag Cup" desktop application creativity competition 2022
Esp32 construction engineering add components
属性关键字Aliases,Calculated,Cardinality,ClientName
The meaning of variables starting with underscores in PHP
[daily training] 648 Word replacement
得物客服热线的演进之路
Indoor ROS robot navigation commissioning record (experience in selecting expansion radius)
call undefined function openssl_cipher_iv_length
postgresql array类型,每一项拼接
How far can it go to adopt a cow by selling the concept to the market?
Redis 核心数据结构 & Redis 6 新特性详
AI人才培育新思路,这场直播有你关心的
2022-7-6 sigurg is used to receive external data. I don't know why it can't be printed out
[high frequency interview questions] difficulty 2.5/5, simple combination of DFS trie template level application questions
LIS longest ascending subsequence problem (dynamic programming, greed + dichotomy)
Esp32 series column
Leetcode simple question sharing (20)
[1] ROS2基础知识-操作命令总结版
带你掌握三层架构(建议收藏)