0

I have a collection of Movie objects in a HashSet<Movie>. Movie type has properties such has Name, Year, Length, Genre, etc.

I also has user profiles stored in individual files. I want to have each user to have a number of favorite movies.

But I am not sure how to "connect"/reference these movies inside the user profiles.

Should I just rely on names?

What's the best way to store the favorite movies in these individual user profiles? I can't think of any other than using names, but this feels like a fragile way. Also movie names are not unique. There are some with the same names.

Any ideas?

Joan Venge
  • 315,713
  • 212
  • 479
  • 689

2 Answers2

1

If you are hoping to link your Movie objects to another object, that I'm assuming are saved out for persistence, then you'd probably want to have some sort of unique identifier (Guid probably) that is associated with the Movie class.

The User class would then have a list of Guids that represent the movies connected as favorites (or you can preload this with the actual movie objects)

Andrew Burgess
  • 5,300
  • 5
  • 30
  • 37
  • Thanks but how can I generate them? What if the name of the movies change later on? Because sometimes they do. – Joan Venge Oct 11 '11 at 20:49
  • When you create the movie object, in the constructor, do something like `id = Guid.NewGuid()` (`Guid` is in the `System` namespace). Only generate the id though if you are making a brand new movie object. You will be able to change the other properties, but as long as you don't change the Guid, you should be fine. – Andrew Burgess Oct 11 '11 at 20:51
  • Thanks, I get the from a website that I parse, so I will know if there is a new movie that's not in my existing list in memory and if so, generate a new guid like you said. But are guids easy to store? Because it will have stuff like UserA: Movie001 -> RatingHeGave, IsFavoriteMovie, etc so I wonder if guids are a huge overhead. – Joan Venge Oct 11 '11 at 20:56
  • No significant overhead, Guids can be stored as strings like this: F3FAD7C4-3845-4A7A-9021-CC6301B107A6 – Andrew Burgess Oct 11 '11 at 20:59
  • Thanks, lastly btw I use serialization. They would be compatible with xml serializers I guess, right? – Joan Venge Oct 11 '11 at 21:01
  • 1
    Yep, it will end up stored as a string like above and read back in properly – Andrew Burgess Oct 11 '11 at 21:02
0

I don't know if the below approach is the best, but have you considered generating a hash value from the byte array that is your movie (when saved to disk or database)?

You can find some ideas on how to do that elsewhere on StackOverflow.

Community
  • 1
  • 1
Philipp Schmid
  • 5,778
  • 5
  • 44
  • 66