Team

Challenge yourself with Team class creation in this lesson.

Moving forward, we observe that the Team class relies solely on the Player class and has no dependencies on any other class. Because the Player class is already in place, we are now ready to develop the Team class. The Team class will incorporate the instances of the Player class we’ve previously constructed.

Press + to interact
UML diagram representing Team class construction
UML diagram representing Team class construction

Once again, keep in mind that the Main class acts as the client and facilitates both the construction and testing of our project. Therefore, along with the code for the Team, we also incorporate this functionality into the Main class.

Crafting compositional structures

A significant aspect of this section involves incorporating Player objects (through composition) into the construction of Team objects. To achieve this, each Team object internally maintains a list of players. The following code segment demonstrates how this is accomplished.

Press + to interact
private List<Player> players;
public Team(String name, String conference) {
this.name = name;
this.conference = conference;
this.players = new ArrayList<>();
teams.add(this);
}

Another aspect is the changes in the Main class. There are two noteworthy changes:

  • As previously mentioned, the team object is now responsible for maintaining a list of its players. Consequently, the Main ...