Suppose the program defines:
class Team
{
public string name;
}A Player can have a field whose type is Team:
class Player
{
public string name;
public Team team;
}The team field can hold a reference to a Team object.
After:
Player player1 = new Player();the team reference field may still be:
nullYou still need a Team object:
Team team1 = new Team();and a relationship assignment:
player1.team = team1;Class diagram:
Player
-------------------------
name : string
team : TeamObject diagram:
player1 : Player -------- team1 : TeamC# field:
public Team team;C# reference assignment:
player1.team = team1;Those representations describe related aspects of the same design.
This:
public Team team;stores a Team reference.
This:
public string team;stores text.
If the model requires an object relationship, use the compatible class type rather than replacing the relationship with a name string.
Before two runtime objects can be connected through a field, the class must define a place for that reference.
That is why class design comes before object relationship assignment.