DDD文件夹结构:不同文件夹中的拆分存储库,还是将所有业务规则保留在通用文件夹中?

发布于 2025-02-05 18:56:58 字数 857 浏览 1 评论 0原文

假设我有一堆用于抽象模块的集成:解析器订购

您如何说在DDD的角度组织文件夹结构的更好方法?

ordering/
----abstract.py
parser/
----abstract.py
integration1/
----ordering.py  # depends on ordering.abstract
----parser.py  # depends on parser.abstract
integration2/
----ordering.py  # depends on ordering.abstract
----parser.py  # depends on parser.abstract

ordering/
----abstract.py
----integration1.py  # depends on abstract
----integration2.py  # depends on abstract
parser/
----abstract.py
----integration1.py  # depends on abstract
----integration2.py  # depends on abstract

抽象文件处理我的应用程序的业务规则(我们如何验证数据,如何协调请求响应周期等)以及集成文件处理第三方的业务规则(我们如何解释他们发送的数据,我们如何以他们期望的方式准备数据等)。

就像我看到的那样,每个集成充当某种存储库,其核心实现依赖于Abstract.py

我倾向于使用第一种方法,因为我们明确将这些域分开,但同时所有文件都具有相同的目的。

你的想法是什么?

Let's say I have a bunch of integrations that uses to abstract modules: parser and ordering.

How would you say is the better approach for organizing the folder structure in a DDD point of view?

ordering/
----abstract.py
parser/
----abstract.py
integration1/
----ordering.py  # depends on ordering.abstract
----parser.py  # depends on parser.abstract
integration2/
----ordering.py  # depends on ordering.abstract
----parser.py  # depends on parser.abstract

OR

ordering/
----abstract.py
----integration1.py  # depends on abstract
----integration2.py  # depends on abstract
parser/
----abstract.py
----integration1.py  # depends on abstract
----integration2.py  # depends on abstract

The abstract files handles the business rules of my application (how we validate data, how we orchestrate the request-response cycle, etc.) and the integration files handles the business rules of the third parties (how we interpret the data they send, how we prepare the data in a way they expect, etc.).

The way I see, each integration acts as some sort of repository which it's core implementation relies on abstract.py.

I'm inclined for the first approach since we clearly separate these domains, but at the same time all files have the same purpose.

What are your thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

錯遇了你 2025-02-12 18:56:58

您在这里有两个问题:在域层中使用抽象并集成外部上下文。

域中的抽象

抽象文件处理我的应用程序的业务规则(我们如何验证数据,如何协调请求响应周期等)

仅构成abfictions的域层(或软件包)(即其他语言中的接口,您需要查找它的依赖关系的Python类似物并从不同包装中注入其具体实现是一个很好的做法。这使域层与基础架构无关。有一种建筑模式,促进了这种做法,称为端口和适配器架构。您的第一个建议在某种程度上暗示了这种模式。

此外,在DDD中,大多数业务规则都由主要结构执行:汇总根(域中最杰出的实体), Entities value对象。所有这些都以具体类型的形式实现,无需将它们抽象。 存储库域服务等依赖项被抽象。

这里遵循一个潜在的目录方案,当然可以进行修改,尊重我提到的惯例:

.
../domain
..../model
....../entity1
....../value object 1
....../entity2
..../services
....../service1 (interface)
....../service2 (interface)
..../repositories
....../repository1 (interface)
....../repository2 (interface)
../port
..../adapter
....../services
......../service1 (concrete)
......../service2 (concrete)
....../repositories
......../repository1 (concrete)
......../repository2 (concrete)

整合外部环境

...,集成文件处理第三方的业务规则(我们如何解释他们发送的数据,我们如何以他们期望的方式准备数据等)

集成外部上下文(上下文映射在DDD术语中)本身是一个挑战。 DDD的战略性涉及此问题,并建议根据它们之间关系的性质整合上下文的几种选项。所有选项都在努力确保与外部上下文的通信通过一些翻译过程;外部上下文必须不要浸润。

我看到的方式,每个集成都充当某种存储库,其核心实现依赖于Abstract.py。

在DDD中,存储库旨在检索和修改聚合根。 您的翻译的某些确实非常适合存储库模式,您可以在其之后对其进行建模。但是,其中一些可能更好地适合域服务。就像任何其他存储库和域服务一样,您可以将集成的抽象放在域软件包中及其实现。

You have two problems here: using abstractions in the domain layer and integrating external contexts.

Abstractions in the domain layer

The abstract files handles the business rules of my application (how we validate data, how we orchestrate the request-response cycle, etc.)

Constituting the domain layer (or package) only of abstractions (i.e. interfaces in other languages, you need to find the Python analogue for it) of its dependencies and injecting their concrete implementations from different packages is a good practice. That keeps the domain layer independent of infrastructures. There is an architectural pattern promoting this practice called the port and adapter architecture. Your first proposal somewhat connotes this pattern.

Additionally, in DDD, most of the business rules are enforced by the primary constructs: aggregate roots (the most prominent entities in the domain), entities, and value objects. All of these are implemented as concrete types, no need to abstract them away. Dependencies like repositories, domain services, etc. are abstracted.

Here follows a potential directory scheme, open to modifications of course, respecting the conventions I mentioned:

.
../domain
..../model
....../entity1
....../value object 1
....../entity2
..../services
....../service1 (interface)
....../service2 (interface)
..../repositories
....../repository1 (interface)
....../repository2 (interface)
../port
..../adapter
....../services
......../service1 (concrete)
......../service2 (concrete)
....../repositories
......../repository1 (concrete)
......../repository2 (concrete)

Integrating external contexts

... and the integration files handles the business rules of the third parties (how we interpret the data they send, how we prepare the data in a way they expect, etc.)

Integrating external contexts (context mapping in DDD terminology) itself is a challenge. The strategic part of DDD deals with this issue and recommends several options for integrating contexts depending on the nature of the relationship between them. All the options strive to ensure that communication with external contexts go through some translation process; external contexts must not infiltrate unchecked.

The way I see, each integration acts as some sort of repository which it's core implementation relies on abstract.py.

In DDD, repository is meant to retrieve and modify aggregate roots. Some of your translations do fit well into the repository pattern and you can model them after it. However, some of them may fit better into domain services. Just as any other repositories and domain services, you may put the abstractions of the integration ones in the domain package and their implementation in a different one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文