Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I am building game platform content management system where i have the following classes:

Game, GameReview, Video and so on...

Every Game object has list with GameReview objects and every GameReview object has list with Video objects.

public class Game
{
   ......
   private long gameId;
   List<GameReview> gameReviews;
   ......  
}


public class GameReview
{
    .......
    List<Videos> videos;
    ....... 
} 

I also want every GameReview and Video object to has attribute about the game.

So which one do you think is better option:

Option one:

public class GameReview
{
    .........
    private Game game; 
    .........
}

public class Video
{
    .........
    private Game game; 
    .........
}

Option two:

public class GameReview
{
    .........
    private long gameId;
    .........
}

public class Video
{
    .........
    private long gameId;
    .........
}
share|improve this question

closed as off-topic by Jamal Feb 21 at 18:09

If this question can be reworded to fit the rules in the help center, please edit the question.

    
That depends on your backing store. Do you store this in a DB? How do you access a game via an id? –  fge Jan 29 '13 at 21:48
2  
In the object world, option 1 is preferred. Your data layer should have a way of creating the tree using objects, regardless of your storage medium. –  Jeff Vanzella Jan 29 '13 at 22:07
    
This question appears to be off-topic because it is seeking a design review and not a code review (also insufficient code). –  Jamal Feb 21 at 18:09

1 Answer 1

Of course your database is only holding a reference to a game via gameId, so a (relational) database use your option two. But as Jeff already stated it is a implementation detail you don't want to bother with in your object tree.

In case you need the Game far more often than the gameId alone, you should definitely go with option 1. One the other hand if you actually don't need the Game but only the gameId (for creating links, etc) and you have performance issue with fetching the whole game all the time, then and only then you should think about option 2.

share|improve this answer
    
10x for the answer @mnhg. The reason i asked this question is because i was reading not so good things about circular reference models and got a little scared:) –  Joro Seksa Jan 30 '13 at 11:09
    
The circular reference only exist in your classes not in the database, so there should be no issue with this. –  mnhg Jan 30 '13 at 12:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.