实施领域驱动设计

发布于 2024-08-25 21:32:44 字数 246 浏览 13 评论 0原文

有人使用领域驱动设计的技术吗?我最近读了 Eric Evans 的同名书籍(嗯,大部分!),并且有兴趣听听在

我保留的 项目(特别是 C#/C++)中实现了全部/部分内容的人的来信。这个问题是开放式的,因为我希望看到尽可能多的评论,但我特别有几个问题:

1 - 如果语言支持,值类型应该是真正的“值类型”吗?例如 C# 中的结构

2- C# 中是否有任何功能可以使语言和模型之间的关联更清晰(例如,这是一个实体,这是一个聚合等)

Is anyone using the techniques from Domain Driven Design? I've recently read the Eric Evans book of the same name (well, most of it!) and would be interested to hear from anyone who's implemented all/some of it in a project (particularly in C#/C++)

I've kept this question open ended as I'd like to see as many comments as possible, but I have a few questions in particular:

1 - Should value types be real 'value types' if the language supports it? e.g. a struct in C#

2- Is there any feature in C# that makes clearer the association between the language and the model (for instance, this is an entity, this is an aggregate etc.)

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

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

发布评论

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

评论(4

永不分离 2024-09-01 21:32:45

是的!我在项目中使用 DDD(但是我有偏见!)

请记住领域驱动设计提供了指南,而不是严格的答案。只有在尝试之后,您才会了解哪些方面适合您的特定项目。

关于您的问题:

1 - 您可以使用结构 - 但可能存在技术限制阻止您使用它们。例如,您可能拥有引用数千个恰好具有相同值的值对象的实体。在这种情况下,最好使用flyweight对象来降低内存使用

2 - 我建议使用接口(例如IEntityIValueObjectIAggregateRootISpecification >)。泛型和 LINQ 可以帮助解决技术问题,但从设计的角度来看,作用不大。

我创建了一个专门针对 DDD 的 [免费 .NET 库][2],它可能会从中找到想法/灵感。 [在此处阅读更多相关信息。][3](项目已终止)

但我真的很感兴趣:您认为 DDD 的哪些方面会让您受益? “领域驱动”方面,还是实施方面?

Yes! I use DDD in my projects (but I'm biased!)

Remember that Domain Driven Design provides guidelines, not strict answers. It's only after experimenting that you'll understand which aspects work for your specific project.

Onto your questions:

1 - You could use structs - but there may be technical constraints that prevent you using them. For example, you may have entities that references thousands of value objects that happen to have the same values. In this case, it might be better to use a flyweight object to keep memory usage down.

2 - I would suggest using interfaces (e.g. IEntity, IValueObject, IAggregateRoot, ISpecification). Generics and LINQ can help assist in the technical concerns, but are less helpful from a design perspective.

I've created a [free .NET library][2] specifically focused on DDD, which might find ideas/inspiration from. [Read more about it here.][3] (project is dead)

I'm genuinely interested though: Which aspects of DDD do you think will benefit you? The "Domain Driven" aspects, or the implementation aspects?

哀由 2024-09-01 21:32:45

1:取决于。 C# 中的值类型适用于原子基元(int、byte 等)。如果你有类似的东西 - 这是有道理的。如果您的值类型较大,则不会。

2:不。一般来说,这不是语言功能。

我建议接下来阅读:Scott Ambler 的“构建有效的对象应用程序”。

1: depends. Value types in C# are for atomic pimitives (int, byte etc.). If you have something like that - it makes sense. If your value type is larger, no.

2: No. In general this is not a language feature.

I suggest as next read: Scott Ambler's "Building Object Applications That Work".

心是晴朗的。 2024-09-01 21:32:45

1 - 如果语言支持,值类型应该是真正的“值类型”吗?

我认为这个问题的答案将取决于应用程序中的使用情况和其他因素,但是您可能正在寻找的模式是“数据传输对象”,它具有属性、getter 和 setter,但没有其他内容。它可以是结构体也可以是对象,对象可能会简化内存管理问题,特别是在装箱方面。

2- C# 中是否有任何功能可以使语言和模型之间的关联更加清晰(例如,这是一个实体,这是一个聚合等)

I将遵循命名约定,例如“CustomerEntity”、“OrderAggregate”等。

好问题;我期待看到回复。

1 - Should value types be real 'value types' if the language supports it?

I think the answer to that will depend on usage and other factors within your application, but the pattern you're probably looking for is "Data Transfer Object" which has properties, getters, and setters, but nothing else. It can be either a struct or an object, and objects will probably simplify memory management issues, especially with regard to boxing.

2- Is there any feature in C# that makes clearer the association between the language and the model (for instance, this is an entity, this is an aggregate etc.)

I would go with naming conventions, e.g., "CustomerEntity", "OrderAggregate", etc.

Good question; I'm looking forward to seeing responses.

離殇 2024-09-01 21:32:45

1 - 如果语言支持,值类型应该是真正的“值类型”吗?例如,C# 中的结构

不要混淆“值对象”的 DDD 概念和“值类型”的 CLR 概念(C# 中的结构)。前者与设计有关,后者是较低级别的实现考虑,实际上与内存管理有关。

2 - C# 中是否有任何功能可以使语言和模型之间的关联更加清晰(例如,这是一个实体,这是一个聚合等)

在处理实体与值时,是的。我们发现在 C# 中使用 readonly 对于在 DDD 中实现值对象非常有帮助。我们在 Pluralsight 大力拥抱 DDD,我时常在 Pluralsight 博客上发表有关它的博客。事实上,我已经安排了两篇关于 readonly 和 DDD 的博客文章在本周晚些时候发布。

[1] http://blog.pluralsight.com/tag/ddd/

1 - Should value types be real 'value types' if the language supports it? e.g. a struct in C#

Don't get confused between the DDD notion of "Value Object" and the CLR notion of "Value Type" (structs in C#). The former has to do with design, and the latter is a lower-level implementation consideration that really has more to do with memory management than anything else.

2 - Is there any feature in C# that makes clearer the association between the language and the model (for instance, this is an entity, this is an aggregate etc.)

When tackling entities vs. values, yes. We've found that using readonly in C# is very helpful for implementing Value Objects in DDD. We're embracing DDD in a big way at Pluralsight, and I blog about it from time to time on the Pluralsight blog. Indeed I've scheduled two blog entries about readonly and DDD to go out later this week.

[1] http://blog.pluralsight.com/tag/ddd/

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