What's the best way to save movie objects inside other files and associate them with the ones in the actual collection?

筅森魡賤 提交于 2020-01-07 05:43:05

问题


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?


回答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)




回答2:


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.



来源:https://stackoverflow.com/questions/7732033/whats-the-best-way-to-save-movie-objects-inside-other-files-and-associate-them

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!