When planning out my programs, I often start with a chain of thought like so:
A football team is just a list of football players. Therefore, I should
While I don't have a complex comparison as most of these answers do, I would like to share my method for handling this situation. By extending IEnumerable
, you can allow your Team
class to support Linq query extensions, without publicly exposing all the methods and properties of List
.
class Team : IEnumerable
{
private readonly List playerList;
public Team()
{
playerList = new List();
}
public Enumerator GetEnumerator()
{
return playerList.GetEnumerator();
}
...
}
class Player
{
...
}