Hi erveryone,
I got a question I want to clarify by using an example.
I have a Club class and a TennisPlayer class. A club can have many tennisplayers as members to that club, and a tennisplayer can only be member at one club at a time.
My classes would look like this. I simplified the classes for this example.
So my question is, is it right that in the TennisPlayer class the field club has nothing like Club club = new Club()?
Cause if I would do that, every TennisPlayer object I instantiate would have his own Club object which is not logical because there is only one Club object for every club, just like there is in real life no duplicate of the same club, am I right?
I got a question I want to clarify by using an example.
I have a Club class and a TennisPlayer class. A club can have many tennisplayers as members to that club, and a tennisplayer can only be member at one club at a time.
My classes would look like this. I simplified the classes for this example.
C#:
public class Club
{
private List<TennisPlayer> members;
public Club()
{
members = new List<TennisPlayer>();
}
public void AddTennisPlayerAsMember(TennisPlayer tennisPlayer)
{
members.Add(tennisPlayer);
tennisPlayer.Club = this;
}
}
C#:
public class TennisPlayer
{
public string Name;
public Club Club;
public TennisPlayer(string name, Club club)
{
Name = name;
club.AddTennisPlayerAsMember(this);
}
}
So my question is, is it right that in the TennisPlayer class the field club has nothing like Club club = new Club()?
Cause if I would do that, every TennisPlayer object I instantiate would have his own Club object which is not logical because there is only one Club object for every club, just like there is in real life no duplicate of the same club, am I right?