3 ms·
Is it any harder than this? class Team { List<Player> players = new List<Player>(); public void AddPlayer(Player player) { // r
by d0 13y ago
Is it any harder than this?
class Team {
List<Player> players = new List<Player>();
public void AddPlayer(Player player) {
// rule checks here
players.add(player);
}
public IEnumerable<Player> Players {
get { return players; }
}
}
Covers SOLID, DDD, the lot.
One should never inherit the list. Encapsulate perhaps but the list is there as a fundamental structure and to inherit from it would break the encapsulation of the domain model you are constructing and increase efferent coupling.
- robotresearcher 13y agoOne useful improvement: the roster of players should be a set, not a list. Duplicated player bugs become impossible.
- d0 13y agoExcellent point. HashSet<Player> then.