C# program has classes.
(I guess it doesn't matter this is C#. Any OOP language will do.)
one class represents a Team
other class represents a Player
A Team has a "List of Players"
A Player has a "List of Teams" he/she plays on.
Now, when a Player joins a Team, we need to update two lists:
This leaves open the possibility of having an inconsistent set of data. If we update one list and not the other.
Does this make sense? Perhaps a Team thinks a Player is on it's team, but nobody told the Player?
Or a Player thinks it's on a Team, but nobody told the Team?
Can we eliminate this possibility of having an inconsistent set of data?
(or is the data not really inconsistent?)
class TeamPlayer
{
Team team;
Player player;
}
Then, I'd need another class which is a list of all TeamPlayers:class TeamPlayerList
{
List<TeamPlayer> teamPlayerList;
}
Then, I have a class Team,class Team
{
}
And if I want to find out what players are on the Team, I need to search through the TeamPlayerList, and find all the entries for my Team, and glean from that all the Players. public class Team
{
string TeamName;
}
public class Player
{
string PlayerName;
}
public class TeamPlayerList
{
List<Tuple<Team, Player>> TeamPlayerList;
}
To have some database engine in the background would be a big plus.
public class Team
{
List<Player> players;
public void Add(Player player)
{
player.AddTo(this);
players.Add(player);
}
public void Remove(Player player)
{
player.RemoveFrom(this);
players.Remove(player);
}
public ReadOnlyCollection<Player> Players => players.AdReadOnly();
}
public class Player
{
List<Team> team;
internal AddTo(Team team) => team.Add(team);
internal RemoveFrom(Team team) => team.Remove(team);
public ReadOnlyCollection<Team> Teams => teams.AdReadOnly();
}
Players
PlayerID
Name
Address
Phone
Email
Teams
TeamID
Team_Name
Division
Captian
TeamRoster
RosterID
TeamID
PlayerID
PlayerNumber