如果我理解正確的話你的域可以近似這樣的:
- 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
這是正確的。所以從細節的角度來看,將故事或其他表格添加投票標誌是否有意義? – Marco
那麼AddToBallot()去哪了? – Marco
編輯我的意見到上面的答案。很高興我能幫上忙。 –