Issue with class design to model user preferences for different classes
- by Mulone
Hi all,
I'm not sure how to design a couple of classes in my app.
Basically that's a situation:
each user can have many preferences
each preference can be referred to an object of different classes (e.g. album, film, book etc)
the preference is expressed as a set of values (e.g. score, etc).
The problem is that many users can have preferences on the same objects, e.g.:
John: score=5 for filmid=apocalypsenow
Paul: score=3 for filmid=apocalypsenow
And naturally I don't want to duplicate the object film in each user.
So I could create a class called "preference" holding a score and then a target object, something like:
User{
hasMany preferences
}
Preference{
belongsTo User
double score
Film target
Album target
//etc
}
and then define just one target.
Then I would create an interface for the target Classes (album, film etc):
Interface canBePreferred{
hasMany preferences
}
And implement all of those classes.
This could work, but it looks pretty ugly and it would requires a lot of joins to work.
Do you have some patterns I could use to model this nicely?
Cheers,
Mulone