简体   繁体   English

实施领域驱动设计

[英]Implementing Domain Driven Design

Is anyone using the techniques from Domain Driven Design? 有人使用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++) 我最近读过Eric Evans的同名书(好吧,大部分都是这样!)并且有兴趣听一下在项目中实现全部/部分内容的人(特别是在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? 1 - 如果语言支持,值类型应该是真正的“价值类型”吗? eg a struct in C# 例如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.) 2- C#中是否有任何特性使语言与模型之间的关联更加清晰(例如,这是一个实体,这是一个聚合等)

Yes! 是! I use DDD in my projects (but I'm biased !) 我在我的项目中使用DDD(但我有偏见 !)

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. 1 - 您可以使用结构 - 但可能存在阻止您使用结构的技术限制 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. 在这种情况下,最好使用flyweight对象来降低内存使用率

2 - I would suggest using interfaces (eg IEntity , IValueObject , IAggregateRoot , ISpecification ). 2 - 我建议使用接口 (例如IEntityIValueObjectIAggregateRootISpecification )。 Generics and LINQ can help assist in the technical concerns, but are less helpful from a design perspective. 泛型和LINQ可以帮助解决技术问题,但从设计角度来看,它们的帮助较少。

I've created a [free .NET library][2] specifically focused on DDD, which might find ideas/inspiration from. 我创建了一个[免费的.NET库] [2]专门关注DDD,它可能会从中找到想法/灵感。 [Read more about it here.][3] (project is dead) [在这里阅读更多相关信息。] [3] (项目已经死亡)

I'm genuinely interested though: Which aspects of DDD do you think will benefit you? 我真的很感兴趣: 您认为DDD的哪些方面对您有益? The "Domain Driven" aspects, or the implementation aspects? “领域驱动”方面,还是实施方面?

1: depends. 1:取决于。 Value types in C# are for atomic pimitives (int, byte etc.). C#中的值类型用于原子pimitives(int,byte等)。 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. 2:否。通常,这不是语言功能。

I suggest as next read: Scott Ambler's "Building Object Applications That Work". 我建议下一篇:Scott Ambler的“构建对象应用程序”。

1 - Should value types be real 'value types' if the language supports it? 1 - 如果语言支持,值类型应该是真正的“价值类型”吗?

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. 我认为答案取决于应用程序中的使用情况和其他因素,但您可能正在寻找的模式是“数据传输对象”,它具有属性,getter和setter,但没有别的。 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.) 2- C#中是否有任何特性使语言与模型之间的关联更加清晰(例如,这是一个实体,这是一个聚合等)

I would go with naming conventions, eg, "CustomerEntity", "OrderAggregate", etc. 我会使用命名约定,例如“CustomerEntity”,“OrderAggregate”等。

Good question; 好问题; I'm looking forward to seeing responses. 我期待看到回应。

1 - Should value types be real 'value types' if the language supports it? 1 - 如果语言支持,值类型应该是真正的“价值类型”吗? eg a struct in C# 例如C#中的结构

Don't get confused between the DDD notion of "Value Object" and the CLR notion of "Value Type" (structs in C#). 不要混淆“值对象”的DDD概念和“值类型”的CLR概念(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.) 2 - C#中是否有任何特性使语言和模型之间的关联更加清晰(例如,这是一个实体,这是一个聚合等)

When tackling entities vs. values, yes. 在处理实体与价值观时,是的。 We've found that using readonly in C# is very helpful for implementing Value Objects in DDD. 我们发现在C#中使用readonly对于在DDD中实现Value Objects非常有帮助。 We're embracing DDD in a big way at Pluralsight, and I blog about it from time to time on the Pluralsight blog. 我们在Pluralsight上大力采用DDD,我不时在Pluralsight博客上发表这篇文章。 Indeed I've scheduled two blog entries about readonly and DDD to go out later this week. 事实上,我已安排两篇关于readonly和DDD的博客文章将在本周晚些时候发布。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM