views:

8

answers:

0

I need to describe a two-combination of objects. I am trying to describe reciprocal relationships for these objects based on a list of criteria. Think of it this way: I have, say, 3 football players: Andy, Ben, and Charles. For each combination, they are compared with a list of criteria: physical, tactical, skill. The comparison is simple: either Andy is better than Ben, vice versa, or they are equal.

Combinations are [(Andy, Ben), (Ben, Charles), (Andy, Charles)]. Now, for each combination, they are compared on the three criterion described earlier. What is the best way to go about modelling this in an object-oriented way?

Currently, my implementation consists of the following data models:

player
compare
criterion

wherecompareis a object that has these attributes:

compare.id
compare.criterion
compare.player1
compare.player2
compare.better

So in the case of Andy and Ben, we might have:

compare.criterion = 'Skill'
compare.player1 = 'Andy'
compare.player2 = 'Ben'

And if Andy is better, thencompare.better = 'Andy'. Only combinations are concerned here (not permutations), so a helper method that returns acompareobject abstracts this and no permutations are stored, only combinations.

With this, I have a data model that works, but I wonder if there is a better and easier way to do this?