Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the java three-tier architecture and the DDD hierarchical architecture

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article focuses on "what is the three-tier architecture of java and the hierarchical architecture of DDD". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "what is the three-tier architecture of java and the hierarchical architecture of DDD?"

Three-tier architecture

The traditional three-tier architecture is mainly divided into business interface layer, business logic layer and data access layer.

Service interface layer: mainly the definition of API, including resource path definition, request message acceptance, response message return, request coding and so on.

Business logic layer: mainly do business logic processing, this layer includes data mapping DTO to VO, business core logic writing, combining different data warehouses, doing business logic

Data access layer: mainly do data storage, including data mapping VO to PO, data interface definition, mapping XML writing.

DDD hierarchical architecture

DDD hierarchical architecture can also be called four-tier architecture, which is mainly composed of user interface layer, application layer, domain layer and basic layer.

User interface layer: responsible for displaying information to users and interpreting user instructions, such as users, programs, automated scripts, batch scripts, etc.

Application layer: mainly used to coordinate multiple aggregated services and domain objects to complete service orchestration and composition, can be transferred locally or remotely, including permission verification, transaction control, anti-duplication idempotency, etc., do not put the core business logic here

Domain layer: implement core logic, including aggregation roots, entities, value objects, domain services, including business extension points, verification rules, composite aggregation services and other related functions

Basic layer: provide general technology and basic services, including some third-party tool classes, caches, databases, files, etc., using dependency inversion design, decoupling from other layers.

Evolvement

Evolution from three-tier architecture to DDD architecture, mainly in logic layer and database access layer

Add DTO to make front-end data more available and flexible

The business logic layer of the three-tier architecture is changed to the application layer and the domain layer, so that the business logic is not confused and the application responds quickly to the changes in the front end.

The design changes of the basic layer and the data access layer decouple the basic resources by relying on inversion, and deal with the changes of the mainstream technology.

Project structure

User interface layer

Assembler:DTO converts and exchanges data with entity objects, and appears at the same time as DTO

Dto: data transmission carrier. DTO can isolate domain objects from the outside world.

Facade: coarse interface granularity definition, which sends requests to multiple application services for processing

Application layer

Event: mainly stores event-related codes, including two subdirectories, publish and subscribe, and publishes and subscribes related codes. Here you can get subscriptions for services in different domains or between microservices.

Service: application service, which mainly encapsulates, orchestrates and encapsulates external services to provide coarse-grained services. It is also an independent business logic.

Domain layer

Aggregate: the root directory of the aggregation package, named after the name of the aggregation, in which entities, aggregation roots, entities, value objects, and domain services can be defined and split into micro services independently.

Entity: store aggregate root, entity, value object, factory schema related code, unified entity related logic, all in this class, using hyperemia mode

Event: stores event entities and logic codes related to event activities

Service: domain services, business logic combined according to different entities

Repository: code for aggregating queries and persisting domain objects

Basic layer

Config: mainly stores configuration-related codes, such as configurations within springboot automatic configuration and integration of third-party components

Util: mainly stores basic code such as platform, development framework, message, database, cache, file, bus, gateway, third-party class library, general algorithm, etc. You can create different subdirectories for different resource categories.

Sample code

At this point, I believe you have a deeper understanding of "what is the java three-tier architecture and DDD hierarchical architecture". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report