1: scope and importance of entity use
The concept discussed in this article is actually relatively simple, but it is very important and common in practical project applications. Our projects generally adopt a layered architecture. Some three layers may have five layers or other ways to organize the system architecture, but we must always design the system architecture according to the pattern, we can reuse and accept maintenance. With the popularity and wide application of ORM, various ORM frameworks have emerged in the industry, and large software companies have developed their own frameworks, basically, the concept of object-centered is followed in terms of usage, that is, the table in the relational database is the operation object. Complex operations may also include join queries for multiple tables. According to the guiding constraints in the layered architecture design, we should try our best to use Entity between system modules for data transmission. Of course, there may not be such a simple project with no specific characteristics in the world. We only discuss traditional information system projects. [Wang qingpei has all rights reserved. For more information, see the data transmission in the layered architecture. Figure 1:
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1I63035V-0.jpg "/>
This picture may be a bit simple, but it can be used to understand the concept of a large body. The transfer of objects between layers ensures many risks caused by Data Table Data transmission. Typically, Rows indexes and Columns indexes are used. After the code of the DAL layer is changed, the risks are transmitted to the BLL layer and UI Layer. This increases the cost for later maintenance of the system. If we use Entity to transmit data, there will be no such problems or the problems will be much lighter. Of course, this requires coding constraints in the project development process. Programmers may habitually use Data Table.
2: Relationship between objects and interfacesMost systems need to display data on the interface, and then securely collect data from the interface and place it in the entity for addition, deletion, modification, and query operations. This kind of work may be written by common programmers or intern programmers, who do not realize that this is a repetitive work. However, programmers who come over will think of this connection carefully. Appropriate encapsulation will greatly reduce the development efficiency. Let's take a look at how objects are assigned values: Figure 2:
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1I6302419-1.jpg "/>
This is a simple code segment I found. It is to assign the value in the control on the interface to the object, and then perform BLL business logic operations. In this case, I still have few attributes. Some may have dozens of attributes that need to be taken from the interface and are the verified data values. Therefore, two aspects of development are indeed time-consuming. One is Data Validity verification, and the other is Data assignment. Of course, the value assignment of the data is reversed. Assigning the values in the object to the control is also a waste of time.
3: Use the Model between Model and UIControl to expand the Basic FrameworkFrom the above questions, we seem to understand something. Let's first look at the simple encapsulation.
1
:The primary problem is to encapsulate the control twice and combine the input control with the verification control to automatically verify the effectiveness of the data. This way, programmers can reduce a lot of verification code during development, you don't have to look for regular expressions and use various verification controls.
2
:The following describes how to associate a widget with an object property. This association has two actions: an object assigned to a widget and a control assigned to an object. Let's take a look at how to assign a value to an object and assign a value to an object. A more important issue is the data type. How to assign a value to a property in a control, this is directly related to the construction of the object. The construction of the object is mostly based on the requirements of the ORM, if your ORM uses a more traditional reflection to assign values to the object data, the object is isolated, and only reflection can be used to assign values. In fact, my idea is to improve the Abstraction Level to classify entities and drag object assignments into the runtime. This advantage is obvious. (For more information, see my article "using abstraction and Polymorphism to implement a non-reflection green ORM framework".) It improves performance from the ORM perspective, from a larger point of view, we can draw on the Module division and large proportion structure in the field-driven design to abstract entities and then become very powerful, if a domain model can be reasonably presented in a layered architecture, it is absolutely amazing. In fact, the data type here depends on the programmer's own judgment. If it is an integer, the verification rules of the control cannot be set to others. In this way, the value of the control can be safely converted (as) Based on the Data Type of the object ). The entity assignment is similar to that of the control. You just need to find the specific attribute based on a certain identifier of the control and set it. Let's take a look at a small example I wrote: Figure 3: entity Graph
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1I630A63-2.jpg "/>
This entity has many attributes. Due to the time relationship, I only use two attributes for demonstration. Interface Diagram
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1I63013A-3.jpg "/>
Code Conversion Diagram
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1I6302451-4.jpg "/>
Conclusion: through such encapsulation, we have indeed reduced a lot of repetitive work, and I have seen that this effect is very obvious. In this way, the entity is encapsulated smoothly, sent to BLL, and then the entity is assigned a value to the control. Although simple, it is very useful. You can refine the data table control to encapsulate it. I think that effect is more obvious. The above is my little experience in the basic library, and I hope you can use it.
This article is from the pattern driven the world blog, please be sure to keep this source http://wangqingpei557.blog.51cto.com/1009349/876261