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

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

Apr 18, 2017 am 09:07 AM

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Perfect Number in Java Perfect Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Random Number Generator in Java Random Number Generator in Java Aug 30, 2024 pm 04:27 PM

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Weka in Java Weka in Java Aug 30, 2024 pm 04:28 PM

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Smith Number in Java Smith Number in Java Aug 30, 2024 pm 04:28 PM

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

Java Spring Interview Questions Java Spring Interview Questions Aug 30, 2024 pm 04:29 PM

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Break or return from Java 8 stream forEach? Break or return from Java 8 stream forEach? Feb 07, 2025 pm 12:09 PM

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

TimeStamp to Date in Java TimeStamp to Date in Java Aug 30, 2024 pm 04:28 PM

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Create the Future: Java Programming for Absolute Beginners Create the Future: Java Programming for Absolute Beginners Oct 13, 2024 pm 01:32 PM

Java is a popular programming language that can be learned by both beginners and experienced developers. This tutorial starts with basic concepts and progresses through advanced topics. After installing the Java Development Kit, you can practice programming by creating a simple "Hello, World!" program. After you understand the code, use the command prompt to compile and run the program, and "Hello, World!" will be output on the console. Learning Java starts your programming journey, and as your mastery deepens, you can create more complex applications.

See all articles