简析三层架构
三层架构3-tier architecture 通过几个问题,来初步的学习一下三层架构。 1、什么是三层架构 2、应用场景为什么要用三层架构? 3、三层作用 4、各个层之间的关系 5、三层联系引用 6、各层是如何调用的 7、三层和二层的对比 这几个都是学习三层中最基本的问题
三层架构——3-tier architecture
通过几个问题,来初步的学习一下三层架构。1、什么是三层架构 2、应用场景——为什么要用三层架构? 3、三层作用 4、各个层之间的关系 5、三层联系——引用 6、各层是如何调用的 7、三层和二层的对比 这几个都是学习三层中最基本的问题,只有把这些问题搞清楚,才算是打开了三层的门。
1、什么是三层架构
在软件体系架构设计中,分层式结构是最常见,也是最重要的一种结构。三层从下至上分别为:数据访问层(DAL)、业务逻辑层(BLL)、表示层(UI)。
表现层(UI):展现给用户的界面,即用户在使用一个系统的时候他的所见所得。
业务逻辑层(BLL):对数据层的操作,对数据业务逻辑处理。
数据访问层(DAL):对数据库的操作,数据的增添、删除、修改、查找等。
2、应用场景——为什么要用三层架构?
为什么要用三层架构?
解耦!
不是所有的程序都需要使用三层架构,没必要把简单的问题复杂化。
先来说一下解耦,举例:修电脑
电脑硬盘坏了?我们要做的就是换掉电脑硬盘
内存条坏了?只要换内存条就好
这些部件出现问题,都不会影响别的部件的正常使用,这个就是让他们之间解耦。而和电脑不同的收音机,任何部件坏了,都会影响别的部件,这个体现的就是他们之间的耦合比较高。从这个例子里面就可以看出解耦的好处,在三层中就是用的解耦的思想。
3、三层作用
数据访问层:从数据源加载(Select),写入(Insert/Update),删除(Delete)数据。仅限于和数据源打交道,让程序简单明了。
显示层(UI):向用户展现特定业务数据,采集用户的输入信息和操作。
原则:用户至上,兼顾简洁。
业务逻辑层(BLL):从DAL中获取数据,以供UI显示用,从UI中获取用户指令和数据,执行业务逻辑、从UI中获取用户指令和数据,通过DAL写入数据源。
4、各个层之间的关系:
UI->BLL->UI:UI提供数据指令到业务逻辑,若自己可以搞定,则直接反馈到UI
UI->BLL->DAL->BLL->DAL:UI提供用户指令和数据,提出请求并搜集一定的数据BLL,BLL处理不了时,要访问数据源,则转给DAL
5、三层联系——引用
以登陆为例子,说明三层之间的引用关系:
实体层(entity):定义的用户名和密码。
U层:向对应的文本框中输入账号和密码
B层:判断U层输入的账号和密码是否存在。
D层:连接数据库的语句,查询数据库。
他们之间的联系是通过实体传递来进行的,。
DAL所在程序集不引用BLL和UI
BLL需要引用DAL
UI直接引用DAL,可能引用BLL
非常忌讳互相引用,为了避免这个问题所有出现了实体层(业务数据模型,里面的数据和数据库的有所差异)
应用原则:
DAL只提供基本的数据访问,不包含任何业务相关的逻辑处理。UI只负责显示和采集用户操作,不包含任何的业务相关的逻辑处理,BLL负责处理业务逻辑,通过获取UI传来的操作指令,决定执行业务逻辑,在需要访问数据源的时候直接交给DAL处理。处理完成后,返回必要数据给UI。
6、各层是如何调用的
表示层(UI)是用户需要的界面,用户有什么需求都是在这个上面进行的改动,一旦有改动,首先U层向B层发送用户请求的说明,到达B层,B层再将U层的用户请求发送到D层,D层接受到用户请求的指令后,对它进行处理,发送数据反馈到B层,B层再发给U层,将这一变化反应出来。
举例:
小菜和大鸟吃羊肉串的例子,小菜和大鸟就是用户,服务员为表示层(U层),烤肉师父为业务逻辑层(U层引用B层的方法或者参数),老板娘为数据访问层(D层),负责给烤肉师父从库房拿烤串。大鸟点了羊肉串5串(参数),服务员把羊肉串5串(参数传递)传递给烤肉师父(数据请求),烤肉师父再传递给老板娘(对参数进行处理),老板娘得到请求后,拿羊肉串给烤肉师父(数据反馈),烤肉师父将烤好的羊肉串给服务员(数据反馈),服务员再将5串羊肉串给大鸟(U层展现出来),他们之间通过调用来实现联系。
7、三层PK二层
二层架构:
业务逻辑简单,没有真正的数据存储层
三层架构:
抽象出业务逻辑层,当业务复杂到一定程度,当数据存储到相应的存储介质,数据存储脱离开业务逻辑,把业务逻辑脱离开UI单独存在,UI只需要呼叫业务访问层,就可以实现跟用户的交互。
三层的好处:
1、开发人员可以只关注整个结构中的其中某一层;
2、可以很容易的用新的实现来替换原有层次的实现;
3、可以降低层与层之间的依赖;
4、有利于标准化;
5、利于各层逻辑的复用。
6、结构更加的明确
7、在后期维护的时候,极大地降低了维护成本和维护时间。
这几点的中心思想就是“高内聚,低耦合”,类之间的耦合越弱,越有利于复用,一个处在弱耦合的类被修改,不会对有关系的类造成波及。
以上是对三层的简单认识,有的地方可能写的不对,欢迎指出!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The concept of deep learning originates from the research of artificial neural networks. A multi-layer perceptron containing multiple hidden layers is a deep learning structure. Deep learning combines low-level features to form more abstract high-level representations to represent categories or characteristics of data. It is able to discover distributed feature representations of data. Deep learning is a type of machine learning, and machine learning is the only way to achieve artificial intelligence. So, what are the differences between various deep learning system architectures? 1. Fully Connected Network (FCN) A fully connected network (FCN) consists of a series of fully connected layers, with every neuron in each layer connected to every neuron in another layer. Its main advantage is that it is "structure agnostic", i.e. no special assumptions about the input are required. Although this structural agnostic makes the complete

Some time ago, a tweet pointing out the inconsistency between the Transformer architecture diagram and the code in the Google Brain team's paper "AttentionIsAllYouNeed" triggered a lot of discussion. Some people think that Sebastian's discovery was an unintentional mistake, but it is also surprising. After all, considering the popularity of the Transformer paper, this inconsistency should have been mentioned a thousand times. Sebastian Raschka said in response to netizen comments that the "most original" code was indeed consistent with the architecture diagram, but the code version submitted in 2017 was modified, but the architecture diagram was not updated at the same time. This is also the root cause of "inconsistent" discussions.

Deep learning models for vision tasks (such as image classification) are usually trained end-to-end with data from a single visual domain (such as natural images or computer-generated images). Generally, an application that completes vision tasks for multiple domains needs to build multiple models for each separate domain and train them independently. Data is not shared between different domains. During inference, each model will handle a specific domain. input data. Even if they are oriented to different fields, some features of the early layers between these models are similar, so joint training of these models is more efficient. This reduces latency and power consumption, and reduces the memory cost of storing each model parameter. This approach is called multi-domain learning (MDL). In addition, MDL models can also outperform single

SpringDataJPA is based on the JPA architecture and interacts with the database through mapping, ORM and transaction management. Its repository provides CRUD operations, and derived queries simplify database access. Additionally, it uses lazy loading to only retrieve data when necessary, thus improving performance.

This is an era of AI empowerment, and machine learning is an important technical means to achieve AI. So, is there a universal machine learning system architecture? Within the cognitive scope of experienced programmers, Anything is nothing, especially for system architecture. However, it is possible to build a scalable and reliable machine learning system architecture if applicable to most machine learning driven systems or use cases. From a machine learning life cycle perspective, this so-called universal architecture covers key machine learning stages, from developing machine learning models, to deploying training systems and service systems to production environments. We can try to describe such a machine learning system architecture from the dimensions of 10 elements. 1.

Paper address: https://arxiv.org/abs/2307.09283 Code address: https://github.com/THU-MIG/RepViTRepViT performs well in the mobile ViT architecture and shows significant advantages. Next, we explore the contributions of this study. It is mentioned in the article that lightweight ViTs generally perform better than lightweight CNNs on visual tasks, mainly due to their multi-head self-attention module (MSHA) that allows the model to learn global representations. However, the architectural differences between lightweight ViTs and lightweight CNNs have not been fully studied. In this study, the authors integrated lightweight ViTs into the effective

For the next generation of centralized electronic and electrical architecture, the use of central+zonal central computing unit and regional controller layout has become a must-have option for various OEMs or tier1 players. Regarding the architecture of the central computing unit, there are three ways: separation SOC, hardware isolation, software virtualization. The centralized central computing unit will integrate the core business functions of the three major domains of autonomous driving, smart cockpit and vehicle control. The standardized regional controller has three main responsibilities: power distribution, data services, and regional gateway. Therefore, the central computing unit will integrate a high-throughput Ethernet switch. As the degree of integration of the entire vehicle becomes higher and higher, more and more ECU functions will be slowly absorbed into the regional controller. And platformization

The learning curve of the Go framework architecture depends on familiarity with the Go language and back-end development and the complexity of the chosen framework: a good understanding of the basics of the Go language. It helps to have backend development experience. Frameworks that differ in complexity lead to differences in learning curves.
