Pergunta

I have a Story that can have one nominator assigned to it. A nominator can be assigned to multiple stories. The nominator can move a story to their ballot (not a story can only belong to their nominators ballot). I've always done data driven apps in the past, so unfortunately I am already thinking about how to handle the ballot. Since the Story table has a nominator id assigned to it, it kind of makes sense to add a IsBallot flag to the table. But now in my actual domain design, the story has a behavior to add itself to a ballot (which seems weird since there are rules tied to the nominator on this). I guess it could ask the nomintaor if it can add itself to the ballot. My second option is to have another table StoryBallot that contains the nominator id and story id. whats weird here is the story already contains the nominator id and this new table also has it.

any ideas or suggestions would be great!

Foi útil?

Solução

If I understand correctly your domain could be modeled like this:

- 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

Using Domain-Driven Design we wouldn't think of tables at all. We would think of Aggregates and maybe even Bounded Contexts. But to not overcomplicate things, I'll keep it at the Aggregate-Level:

We could have two Aggregate Roots:

1. Nominator (who knows all their stories)
2. Ballot (which knows all their nominated stories as 
   well as the respective nominators)

The story itself maybe wouldn't be accessed directly at all but only through the Nominator or Ballot respectively.

Is there a reason for a story to exist without it being owned by a nominator or nominated to a ballot? If not, make it inaccessible by itself and only expose e.g. Nominator.GetStories(), Nominator.GetNominatedStoriesFor(ballot) and/or Ballot.GetStories()

To add a story to a ballot, I'd either expose Nominator.NominateStory(storyId, ballotId) or Ballot.Add(storyId).

When it comes to storing in a database, I'd probably have a table NominatedStories with ballotId and storyId and a table Stories with story details and nominatorId

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top