如果我理解正确,您的域可以这样建模:
- A Nominator has stories
- A Nominator can nominate Stories for a Ballot
- A Ballot knows all its Stories and their respective Nominator
- A Story knows its Nominator
使用领域驱动设计,我们根本不会想到表格。我们会想到聚合,甚至可能会想到有界上下文。但为了不使事情过于复杂,我将把它保持在聚合级别:
我们可以有两个聚合根:
1. Nominator (who knows all their stories)
2. Ballot (which knows all their nominated stories as
well as the respective nominators)
故事本身可能根本无法直接访问,而只能分别通过提名人或选票访问。
一个故事没有被提名人拥有或被提名投票,是否有理由存在?如果不是,则使其无法自行访问,并且仅公开例如Nominator.GetStories()
,Nominator.GetNominatedStoriesFor(ballot)
和/或Ballot.GetStories()
要在选票中添加故事,我会公开Nominator.NominateStory(storyId, ballotId)
或Ballot.Add(storyId)
.
当谈到在数据库中存储时,我可能会有一个NominatedStories
带有ballotId
和storyId
的表,以及一个Stories
带有故事细节的表和nominatorId