Three-tier architecture to see java

  Introduction to the
  
  three-tier architecture model
  
  Three-tier architecture model: 3-tier architecture (3-tier architecture) The usual three-tier architecture is to divide the entire business application into: interface layer (User Interface layer), business logic layer (Business Logic Layer) , Data access layer (Data access layer). The purpose of distinguishing layers is for the idea of ​​"high cohesion and low coupling". In software architecture design, the layered structure is the most common and the most important structure. The layered structure recommended by Microsoft is generally divided into three layers, from bottom to top: data access layer, business logic layer (also known as domain layer), and presentation layer.
  
  Presentation layer (JSP): The
  
  presentation layer, also known as the interface layer, is located at the outermost layer (uppermost layer), closest to the user. It is used to display data and receive data input by users, and provide users with an interactive operation interface.
  
  Business layer (logic layer, service layer):
  
  The business layer (Business Logic Layer) is undoubtedly the core value of the system architecture. Its focus is mainly on the system design related to business requirements such as the formulation of business rules and the realization of business processes, that is to say, it is related to the domain logic that the system responds to. In many cases, the business logic is also The layer is called the domain layer. For example, in the book "Patterns of Enterprise Application Architecture", Martin Fowler divides the whole architecture into three main layers: presentation layer, domain layer and data source layer. Eric Evans, a pioneer in domain-driven design, made a more detailed division of the business logic layer, subdivided into an application layer and a domain layer, and further separated the domain logic and domain logic solutions through layering. The position of the business layer in the system architecture is critical. It is located between the data access layer and the presentation layer, and serves as a link between the data exchange and the presentation. Because the layer is a weakly coupled structure, the dependence between layers is downward. The bottom layer is "ignorant" to the upper layer. Changing the design of the upper layer has no effect on the bottom layer it calls. If the idea of ​​interface-oriented design is followed in layered design, then this downward dependency should also be a weak dependency. Therefore, without changing the interface definition, the ideal layered architecture should be an extractable and replaceable "drawer" architecture. Because of this, the design of the business layer is especially critical for an architecture that supports scalability, because it plays two different roles. For the data access layer, it is the caller; for the presentation layer, it is the callee. The relationship between dependence and being depended on is tangled in the business layer. How to realize the decoupling of the dependence relationship is the task left to the designer in addition to the realization of business logic.
  
  Persistence layer (DAO):
  
  The persistence layer, sometimes referred to as the data access layer, is mainly responsible for database access, and can access the database system, binary files, text documents, or XML documents. Adopt DAO mode to establish entity class and database table mapping (ORM mapping). The simple saying is to implement the select, insert, update and delete operations on the data table. If you want to add ORM elements, then it will include the mapping between the object and the data table, as well as the persistence of the object entity.
  
  The difference between layer 3 and MVC:
  
  Many people easily confuse the three-layer model with the MVC model. The most difference between layer 3 and MVC is that there is no concept of a controller in layer three. Although they are also at the architectural level, the three layers are the same as MVC in that they all have a presentation layer, but their difference lies in the other two layers. MVC does not regard the logical access of the business as two layers, which is the main difference between using a three-tier architecture or MVC to build a program. Of course, the concept of Model is also mentioned in the third layer, but the concept of Model in the three-tier architecture is different from the concept of Model in MVC. The typical Model layer in the "three-tier" is composed of entity classes, and MVC Here, it is composed of business logic and access data.
  
  In the three layers, the JSP and Servlet codes belong to the presentation layer, the business logic layer is the entity class that completes the business rules, and the data access layer is JDBC and other codes. Schematic diagram: The   three-layer architecture of the
  
  technical picture
  
separates the business responsibilities of different layers more Thoroughly, the logic layer does not contain a bit of view layer code, and the same data layer should not contain a bit of logic layer code, because if the code of other layers is included, it cannot be completely decoupled, and there is still a certain degree of coupling Sex.
  
  The three-tier architecture better implements modular programming, and the system designed with the three-tier architecture is easier to expand and replace, especially now that there is more than one device on the PC side, and if it is not properly layered, it cannot adapt to access by multiple devices. For example, we use the jsp + Servlet for the presentation layer, which is web-oriented. If the web is not going to be done someday, the entire presentation layer needs to be replaced with a graphical display on the desktop. If you use a three-tier architecture, you only need to replace the presentation Only the layer can be used, and both the logic layer and the data layer can be reused. If there is no layering, the various modules are coupled together and cannot be reused. You can only re-write a system that adapts to the desktop, which is very time-consuming and labor-intensive.
  
  We all know that WebService is a cross-programming language and cross-operating system platform remote calling technology. If a system is designed using a three-tier architecture, then the logical layer can be shared by WebService to applications written in other languages.
  
  The recently popular WeChat applet accesses the server through https, which requires the server to return json data, then we can receive this access in the Servlet in the view layer, and return json data after processing.   Advantages
  
  and disadvantages of the three-tier development model
  
:
  
  1. Developers can only focus on one of the layers in the entire structure;
  
  2. It is easy to replace the implementation of the original hierarchy with a new implementation;
  
  3. Can reduce the layers Interdependence;
  
  4. Conducive to standardization;
  
  5. Conducive to the reuse of logic at all levels.
  
  6. The structure is more clear.
  
  7. In the later maintenance period, the maintenance cost and maintenance time are greatly reduced.
  
  Disadvantages:
  
  1. The performance of the system is reduced. This is self-evident. If you do not use a layered structure, many businesses can directly access the database to obtain the corresponding data, but now must be completed through the middle layer.
  
  2. Sometimes it will lead to the modification of the cascade. This modification is especially reflected in the top-down direction. If a function needs to be added in the presentation layer, in order to ensure that its design conforms to the layered structure, it may be necessary to add corresponding code in the corresponding business logic layer and data access layer.
  
  For example, if a restaurant adds a dish, the menu (UI), chef (BLL), and purchase (DAL) must be processed accordingly.

Guess you like

Origin www.cnblogs.com/avav12356/p/12717009.html