I am working on a Java project and I would like to a really clean "Object Oriented" design (the best I can...).
But I am struggling to understand how each object should reference the others.
Let's take the simple standard chess game example :
- Each player has a given number of chess pieces.
- Each piece belongs to 1 player
In my application, I will probably need to be able to retrieve the information in both way :
- Access the owner directly from the Piece
- Access all the owned pieces directly from a player
Here are my questions :
- What would be the best design ? Each entity should reference the other one(s) ?
- Or X-referencing is just always bad ? Should I always access the objects in "single way" ?
- Maybe should I make another class that manage the mapping between the Piece and the Players ?
I do not like the X-ref solution, because it basically duplicate the information and it can potentially create inconsistency and a lot of work overload. But can it be avoided ?
I know those questions are a bit fuzzy but I do not think I can figure out alone ! Please help !
Thanks anyone.
Aucun commentaire:
Enregistrer un commentaire