当你有一个m-to-m与第三个关联的两个Aggregrate Roots时,你如何过滤第三个关联?

时间:2015-09-12 19:41:15

标签: design-patterns many-to-many domain-driven-design

我有以下3个域对象:CompetitionSeasonMatch

Competition有很多Seasons
Season有很多competitions CompetitionSeason的汇总根,因为如果没有Season

Competition就不能存在

示例:
Competition
英超联赛 - >第1季,第2季 足总杯 - >第1季,第2季 联赛杯 - >第1季,第2季

Season
第1季 - >英超,足总杯,联赛杯
第2季 - >英超,足总杯,联赛杯

Competition也有很多Matches Season也有很多Matches

competition->getMatches()返回matches每个season的所有内容 season->getMatches()会为每matches

返回所有competition

问题。在DDD的背景下,获得比赛和赛季组合的所有比赛的最佳方法是什么?例如,仅来自英超第1季的比赛?

据我所知,有3种方法:

  1. 使用循环查找将Season传入Premiership->getMatches(Season) Competition Season,然后使用另一个循环查找Matches 属于选定的Competition和传入的Season。可以应用相同的原则,反之亦然Season 1->getMatches(Competition)。但是性能呢?
  2. 实施时间模式。
  3. 只需在repository / dao / / findMatchesByCompetitionAndSeason(Competition, Season)的任何方法中创建,但这不会破坏DDD的目的吗?
  4. 感谢您的时间

1 个答案:

答案 0 :(得分:0)

  

CompetitionSeason的汇总根,因为如果没有SeasonCompetition就不能存在。

我不知道您网域的具体细节,但这种说法听起来并不合适。在阅读完其余问题之后,我认为这就是问题所在。

  

第1季 - >英超,足总杯,联赛杯

这表明Season显然是共同的事情。因此,将季节作为Competition聚合根的一部分并不是一个好主意。尝试重新设计您的模型,以便Season可以独立生存(即使其成为自己的聚合根)并从Competition引用它。

关于您的上一个问题:出于性能原因,您无法在存储库中实现特定的查找程序。这并没有破坏DDD的目的,因为查找程序仍然使用域术语并使用域对象。为您的用例返回正确的域对象只是一种技术问题,因此是您域的一部分。