views:

278

answers:

2

I'm trying to find the best design for the following scenario - an application to store results of dance competitions.

An event contains multiple rounds, each round contains a number of performances (one per dance). Each performance is judged by many judges, who return a scoresheet.

There are two types of rounds, a final round (containing 6 or less dance couples) or a normal round (containing more than 6 dance couples). Each requires slightly different behaviour and data.

In the case of a final round, each scoresheet contains an ordered list of the 6 couples in the final showing which couple the judge placed 1st, 2nd etc. I call these placings "a scoresheet contains 6 placings". A placing contains a couple number, and what place that couple is

In the case of a normal round, each scoresheet contains a non-ordered set of M couples (M < the number of couples entered into the round - exact value determined by the competition organiser). I call these recalls: "a score sheet as M recalls". A recall does not contain a score or a ranking

for example In a final

  • 1st place: couple 56
  • 2nd place: couple 234
  • 3rd place: couple 198
  • 4th place: couple 98
  • 5th place: couple 3
  • 6th place: couple 125

For a normal round The following couples are recalled 54,67,201,104,187,209,8,56,79,35,167,98

My naive-version of this is implemented as

Event - has_one final_round, has_many rounds

final_round - has_many final_performances final_performance - has_many final_scoresheets final_scoresheet - has_many placings

round - has_many perforomances performance has_many scoresheets scoresheet has_many recalls

However I do not like the duplication that this requires, and I have several parallel hierarchies (for round, performance and scoresheet) which is going to be a pain to maintain.

+2  A: 

This requires a little domain knowledge that I don't have, but it seems to me that the ordered vs. non-ordered situation is a little bit irrelevant. If each couple has a score, the ordering in the final round can be deduced from each couple's score, right? That would mean that the final round's data structure would be like every other round's data structure, consisting of multiple (couple, score) sets.

Jim Kiley
A: 

Without knowing in detail what is going on it's hard to give clear advice. However based on what I read it seems your parallel hierarchy may not be necessary.

It's not clear that a final_performance is really different from a performance. I guess they are scored differently; that should be reflected in differences in final_scoresheet, and you probably assumed that you needed to make final_performance different because it had to contain final_scoresheets. Maybe you could have only one performance object, and rather than having the scoresheets contained in the performance have the round object associate scoresheets with performances:

round.getScoresheet(couple,dance)

rather than

round.getPerformance(couple,dance).getScoresheet()

I also wonder if you need objects for placings and recalls: can they just be (ordered) lists of couples retrieved from the scoresheets? If so then you've eliminated three classes.

Containment is preferred over inheritance.

DJClayworth