聚合根是否应在域驱动设计中实现接口 [英] Should an Aggregate Root Implement an Interface in Domain-Driven Design

查看:117
本文介绍了聚合根是否应在域驱动设计中实现接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用域驱动设计和测试驱动开发进行项目。在阅读Evans的DDD书时,我注意到他没有为域中的聚合根定义接口。

I'm working on a project using both domain-driven design and test-driven development. While reading through the DDD book by Evans, I noticed that he did not define interfaces for aggregate roots in the domain.

如果同时执行DDD和TDD,是否应该为每个聚合根定义接口,以使聚合根类易于测试和模拟?如果是这样,我是否还应该为聚合根目录中包含的每个实体定义接口?

If I'm doing both DDD and TDD, should I define interfaces for each aggregate root to make the aggregate root classes easily testable and mockable? If so, should I also define interfaces for each entity contained within the aggregate root as well?

在Google和StackOverflow上的搜索中,我找到了接近的答案对我正在寻找的东西,但是我在进行DDD和TDD时都特别在寻找建议,因为我的假设是在进行TDD时,可测性可能会被到目前为止我所看到的答案所忽略。

From my searches on Google and StackOverflow, I've found answers that come close to what I'm looking for, but I'm specifically look for advice when doing both DDD and TDD because my assumption is that testability, when doing TDD, might be overlooked in the answers that I've seen so far.

推荐答案

否,直接对集合进行测试。聚合本身不应该注入依赖项,如果特定行为需要依赖项,则通常应将其表示为接口。聚合上的接口是不必要的抽象-行为只有一种实现-就是重点。另外,请查看 BDD和DDD -可以看到行为驱动的开发作为TDD的演变,并且与DDD很好地吻合。

No, test directly against the aggregate. The aggregate itself shouldn't have injected dependencies and if a specific behavior requires a dependency, that should usually be expressed as an interface. An interface on an aggregate is a needless abstraction - there is only one implementation of behaviors - that is the point. Also, take a look at BDD and DDD - Behavior-Driven Development can be seen as an evolution of TDD and aligns nicely with DDD.

这篇关于聚合根是否应在域驱动设计中实现接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆