Team
Challenge yourself with the Team class creation.
Moving forward, we observe that the Team
class relies solely on the Player
class and has no dependencies on any other class. As 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.
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
class, 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 maintains a list of players internally. The following code segment demonstrates how this is accomplished.
def __init__(self, name, conference):self.name = nameself.conference = conferenceself.players = []
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
class no longer directly manages a player list; this responsibility is delegated to theTeam
class. Therefore, the player list has been removed from theMain
class’s list of attributes.The
Main
class now oversees a list of teams instead of managing a roster of players. As a result, its main function no longer constructs a list of players but instead initializes a list of teams. ...