samedi 12 septembre 2015

When you have a m-to-m with two Aggregrate Roots of a third association, how do you filter the third association?

I have the following 3 domain objects: Competition, Season, and Match

Competition has many Seasons
Season has many competitions
Competition is the aggregate root for Season because a Season cannot exist without a Competition

Examples:
Competition:
Premiership -> Season 1, Season 2
FA Cup -> Season 1, Season 2
League Cup -> Season 1, Season 2

Season:
Season 1 -> Premiership, FA Cup, League Cup
Season 2 -> Premiership, FA Cup, League Cup

Competition also has many Matches
Season also has many Matches

competition->getMatches() returns all matches for every season
season->getMatches() returns all matches for every competition

Question. In the context of DDD what is the best way to get all matches for a combination of competition and season? For example, matches just from Premiership Season 1?

As far as I am aware there are 3 approaches:

  1. Pass in Season into Premiership->getMatches(Season) with a loop find Competition with that Season, then with another loop find Matches belonging to both the selected Competition and the passed in Season. The same principle can be applied vice versa Season 1->getMatches(Competition). But what about perfomrance?
  2. Implement the Temporal Pattern.
  3. Just create in repository/dao/whatever a method to findMatchesByCompetitionAndSeason(Competition, Season) but doesn't this defeat the purpose of DDD?

Thanks for your time

Aucun commentaire:

Enregistrer un commentaire