I don’t know if this is right place. But I need answer very much.
I’m writing program for tournament management. I have simple problem but for me it is not that clear.
There are many clubs (One club from one city). There are players in club. There are no players without club.
I have Player class and Club class.
Should I keep list of players in Club class or keep players club in his class?
Which way would be better?
Since every Player has a Club, keep a list of Players in the Club class. This makes it fast and simple to enumerate or search all Players in a given Club. However, there’s no reason you can’t also have a reference in the Player class which points to its parent Club. There are valid use cases for having a link in each direction, so do both.
I’m assuming that each Player can only belong to one Club. Things will get a bit more complicated if that is not the case.
An example in C#: (not compiled / tested, so it may have some minor errors)
Now, you can do things like this: