Home > Java > javaTutorial > body text

Summary of the principles and functions of Java three-tier architecture (picture)

黄舟
Release: 2017-04-18 09:07:28
Original
2956 people have browsed it

This article mainly introduces the concepts and functions of Java three-tier architecture. Friends in need can refer to

Three-tier architecture


Three-tier architecture (3-tier application) In the usual sense, the three-tier architecture divides the entire business application into: Presentation layer (UI), business Logic layer (BLL), data access layer (DAL). The purpose of distinguishing levels is the idea of ​​"high cohesion, low coupling".

ConceptIntroduction

1. Presentation layer (UI): In lay terms, it is the interface displayed to the user, that is What a user sees and gains when using a system.

2. Business logic layer (BLL): Operations for specific problems can also be said to be operations on the data layer and processing of data business logic. ​

3. Data Access Layer (DAL): Transactions done by this layer directly operate the database, for data addition, deletion, modification, search, etc.

Overview

In software architecture design, the hierarchical structure is the most common and 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 called domain layer), and presentation layer.

Three-tier structure principle:

In the three levels, the main functions and business logic of the system are processed in the business logic layer.

The so-called three-tier architecture adds an "intermediate layer" between the client and the database, also called component layer. The three-tier system mentioned here does not refer to the three physical layers. It does not mean simply placing three machines, which is the three-tier architecture. It is not only the B/S application that is the three-tier architecture. The three-tier system refers to the logical system. of three layers, even if these three layers are placed on one machine.

The application program of the three-tier system places business rules, data access, legality verification and other tasks in the middle layer for processing. Normally, the client does not directly interact with the database, but establishes a connection with the middle layer through COM/DCOM communication, and then interacts with the database through the middle layer.

The functions of each layer

1:Data data access layer: Mainly for original data (database or text file, etc.) ), rather than the original data, that is to say, it is the operation of data, not the database, specifically providing data services for the business logic layer or presentation layer.

2: Business logic Layer : It is mainly for the operation of specific problems. It can also be understood as the operation of the data layer and the processing of data business logic. If the data layer is the building blocks, then the logic layer is the construction of these building blocks.

3: Presentation layer: mainly represents WEB mode, and can also be expressed as WINFORM mode. WEB mode can also be expressed as: aspx, If the logic layer is quite powerful and complete, no matter how the presentation layer is defined and changed, the logic layer can provide services perfectly.

Specific distinction method

1: Data data access layer: It mainly depends on whether your data layer contains logical processing. In fact, its various Function mainly completes various operations on data files. Don't worry about other operations.

2: Business logic layer: Mainly responsible for the operation of the data layer. That is to say, combine some data layer operations.

3: Presentation layer: Mainly accepts user requests and returns data, providing the client with application access.

Presentation layer

is located in the outermost layer (top layer), closest to the user. Used to display data and receive data input by users, providing users with an interactive interface.

Business Logic Layer

The Business Logic Layer (Business Logic Layer) is undoubtedly the part that embodies the core value of the system architecture. Its focus is mainly on the formulation of business rules, the realization of business processes and other system designs related to business needs. In other words, it is related to the logic of the field (Domain) that the system responds to. Many times, the business logic layer is also called the domain layer.

For example, in the book "Patterns of Enterprise Application Architecture", Martin Fowler divides the entire architecture into three main layers: presentation layer, domain layer and data source layer. As a pioneer in domain-driven design, Eric Evans made a more detailed division of the business logic layer, subdividing it into the application layer and the domain layer, and further separated domain logic and domain logic solutions through layering.

The business logic layer plays a key role in the system architecture. It is located between the data access layer and the presentation layer, and plays a linking role in data exchange. Since 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 impact on the bottom layer it calls.

If the idea of ​​interface-oriented design is followed during layered design, then this downward dependence should also be a weak dependency. Therefore, without changing the interface definition, the ideal layered architecture should be a "drawer" architecture that supports extractability and replaceability. Because of this, the design of the business logic layer is particularly 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 dependence is entangled in the business logic layer. How to realize the decoupling of dependency relationships is a task left to designers in addition to implementing business logic.

Data layer

Data access layer: Sometimes also called the persistence layer, its function is mainly responsible for database access, and can access database systems, binary files, Text document or XML document.

To put it simply, it is to implement the operations of Select, Insert, Update, Delete on the data table. If you want to add ORM elements, it will include mapping between the object and the data table, as well as the persistence of the object entity.

Advantages and Disadvantages

Advantages

1. Developers can only focus on one layer of the entire structure;

2. It can easily replace the original layer implementation with a new one;

3. It can reduce the dependence between layers;

4. There are Conducive to standardization;

5. Conducive to the reuse of logic at each layer.

6. The structure is clearer

7. During later maintenance, the maintenance cost and time are greatly reduced

Disadvantages

1. Reduced system performance. This is self-evident. If a hierarchical structure is not adopted, many businesses can directly access the database to obtain the corresponding data, but now it must be done through the middle layer.

2. Sometimes it will lead to cascading modifications. This modification is particularly reflected in the top-down direction. If a function needs to be added to the presentation layer, in order to ensure that its design conforms to the hierarchical structure, it may be necessary to add corresponding code to the corresponding business logic layer and data access layer.

3. Increased development costs.

Rules

The three-tier structure program does not mean that the project is divided into three modules: DAL, BLL, and WebUI. It is called three-tier. The following questions are in your Inside the project:

1. There are only a few (or no) SQL statements or stored procedures calls in UILyer, and these statements are guaranteed not to modify the data?

2. If Can your project still provide all functions at the Interface/API level if UILyer is removed?

3. Can your DAL be transplanted to other projects with similar environments?

4. Can the three modules be run on different servers?

If not all answers are YES, then your project cannot be regarded as a three-tier program in the strict sense. Three The layer program has some rules that need to be agreed upon:

1. The most critical thing is that the UI layer can only be used as a shell and cannot contain any BizLogic processing procedures

2. The design should start from the BLL Starting from the starting point, not the UI. The BLL layer should implement all BizLogic on the API, in an object-oriented way

3. Whether the data layer is a simple SqlHelper, or with Mapping Classes should be system-independent to a certain degree of abstraction

4. Regardless of whether you use COM+(Enterprise Service) or Remoting, or remote object technologies such as WebService, regardless of whether they are actually deployed to different servers during deployment, at least such considerations must be made during design, and more Furthermore, you have to consider clustering multiple servers through load balancing

So when considering whether a project should apply a three-tier/multi-tier design, you must first consider whether it is really needed? In fact, most of them It is enough to open a WebApplication program, and there is no need to make it so complicated. The multi-layer structure is used to solve truly complex project requirements. The difference between

and MVC

MVC (Model-View-Controller) is a design pattern that we can use to create a distinction between domain objects and UI presentation layer objects.

It is also at the architectural level. The same thing is that they all have a presentation layer, but the difference lies in the other two layers.

The concept of Controller is not defined in the three-tier architecture. This is what I think is the most different. MVC does not regard business logical access as two layers. This is the main difference between using a three-tier architecture or MVC to build a program. Of course. Model is also mentioned in the three-tier architecture, 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. In MVC, it is composed of business logic and access data.

The above is the detailed content of Summary of the principles and functions of Java three-tier architecture (picture). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!