11.15(eleven point one five)

1,什么是三层?UI(表现层): 主要是指与用户交互的界面。用于接收用户输入的数据和显示处理后用户需要的数据。

BLL:(业务逻辑层): UI层和DAL层之间的桥梁。实现业务逻辑。业务逻辑具体包含:验证、计算、业务规则等等。

DAL:(数据访问层): 与数据库打交道。主要实现对数据的增、删、改、查。将存储在数据库中的数据提交给业务层,同时将业务层处理的数据保存到数据库。(当然这些操作都是基于UI层的。用户的需求反映给界面(UI),UI反映给BLL,BLL反映给DAL,DAL进行数据的操作,操作后再一一返回,直到将用户所需数据反馈给用户)每一层都各负其责,那么该如何将三层联系起来呢?

1、单项引用

2、这时候实体层(Entity)来了。(注:当然,实体层的作用不止这些)

Entity(实体层):它不属于三层中的任何一层,但是它是必不可少的一层。

Entity在三层架构中的作用:

1、实现面向对象思想中的”封装”;2、贯穿于三层,在三层之间传递数据;(注:确切的说实体层贯穿于三层之间,来连接三层)3、对于初学者来说,可以这样理解:每张数据表对应一个实体,即每个数据表中的字段对应实体中的属性(注:当然,事实上不是这样。为什么?1>,可能我们需要的实体在数据表对应的实体中并不存在;2>,我们完全可以将所有数据表中的所有字段都放在一个实体里)4、每一层(UI—>BLL—>DAL)之间的数据传递(单向)是靠变量或实体作为参数来传递的,这样就构造了三层之间的联系,完成了功能的实现。但是对于大量的数据来说,用变量做参数有些复杂,因为参数量太多,容易搞混。比如:我要把员工信息传递到下层,信息包括:员工号、姓名、年龄、性别、工资....用变量做参数的话,那么我们的方法中的参数就会很多,极有可能在使用时,将参数匹配搞混。这时候,如果用实体做参数,就会很方便,不用考虑参数匹配的问题,用到实体中哪个属性拿来直接用就可以,很方便。这样做也提高了效率。

————————

1. What is the third floor? UI (presentation layer): it mainly refers to the interface interacting with users. It is used to receive the data input by the user and display the data required by the user after processing.

Bll: (business logic layer): the bridge between UI layer and DAL layer. Implement business logic. Business logic includes verification, calculation, business rules, etc.

Dal: (data access layer): dealing with databases. It mainly realizes the addition, deletion, modification and query of data. Submit the data stored in the database to the business layer, and save the data processed by the business layer to the database. (of course, these operations are based on the UI layer. The user’s needs are reflected to the interface (UI), the UI is reflected to the Bll, the Bll is reflected to the Dal, and the DAL operates the data, and then returns one by one until the data required by the user is fed back to the user.) each layer has its own responsibilities, so how to connect the three layers?

1. Single reference

2. At this time, the entity layer comes. (Note: of course, the role of entity layer is more than that)

Entity layer: it does not belong to any of the three layers, but it is an essential layer.

The role of entity in the three-tier architecture:

1. Realize the “encapsulation” in the object-oriented idea; 2. It runs through the three layers and transfers data between the three layers; (Note: specifically, the entity layer runs through the three layers to connect the three layers) 3. For beginners, it can be understood that each data table corresponds to an entity, that is, the fields in each data table correspond to the attributes in the entity (Note: of course, this is not the case. Why? 1 >, the entity we need may not exist in the entity corresponding to the data table; 2 >, we can put all fields in all data tables in one entity) 4. Data transfer between each layer (UI – & gt; Bll – & gt; DAL) (one-way) It is transferred by variables or entities as parameters, which constructs the relationship between the three layers and completes the realization of the function. However, for a large amount of data, it is complicated to use variables as parameters because there are too many parameters, which are easy to be confused. For example, I want to transfer employee information to the lower level, including employee number, name, age, gender, salary If variables are used as parameters, there will be many parameters in our method. It is very possible to confuse parameter matching when using them. At this time, it will be convenient to use entities as parameters without considering the problem of parameter matching. It is convenient to use which attribute in entities directly. This also improves efficiency.