我有以下3个域对象:Competition
,Season
和Match
Competition
有很多Seasons
Season
有很多competitions
Competition
是Season
的汇总根,因为如果没有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种方法:
Season
传入Premiership->getMatches(Season)
Competition
Season
,然后使用另一个循环查找Matches
属于选定的Competition
和传入的Season
。可以应用相同的原则,反之亦然Season 1->getMatches(Competition)
。但是性能呢?findMatchesByCompetitionAndSeason(Competition, Season)
的任何方法中创建,但这不会破坏DDD的目的吗?感谢您的时间
答案 0 :(得分:0)
Competition
是Season
的汇总根,因为如果没有Season
,Competition
就不能存在。
我不知道您网域的具体细节,但这种说法听起来并不合适。在阅读完其余问题之后,我认为这就是问题所在。
第1季 - >英超,足总杯,联赛杯
这表明Season
显然是共同的事情。因此,将季节作为Competition
聚合根的一部分并不是一个好主意。尝试重新设计您的模型,以便Season
可以独立生存(即使其成为自己的聚合根)并从Competition
引用它。
关于您的上一个问题:出于性能原因,您无法在存储库中实现特定的查找程序。这并没有破坏DDD的目的,因为查找程序仍然使用域术语并使用域对象。为您的用例返回正确的域对象只是一种技术问题,因此不是您域的一部分。