Trying to break up a large aggregate root and just want some help to see if I'm doing it correctly
Consider the following aggregate root "Team" which looks like the following
public class Team : IAggregateRoot
{
public List<Player> Players {get; set;}
// Lots of other properties
public void AddPlayer(Player player){}
public void RemovePlayer(string playerId){}
public void MakePlayerCaptain(string playerId){}
// More Methods
}
So to break that up and make the Team class smaller, I create a new class called Roster
public class Roster
{
public List<Player> Players {get; set;}
public void AddPlayer(Player player){}
public void RemovePlayer(string playerId){}
public void MakePlayerCaptain(string playerId){}
}
And Team now becomes
public class Team : IAggregateRoot
{
public Roster Roster {get; set;}
// Lots of other properties
// More Methods
}
which makes Team smaller and gives me more cohesive models.
But this causes me to peek into the team aggregate root to access roster and make changes. i.e
team.Roster.MakePlayerCaptain()
Or I would just add the methods back onto team and they then call roster object? But then I'm back to having lots of methods (but smaller I guess) in my Team object.
What is the cleanest approach to take with this kind of thing or can anyone link me to some reading around this?
question from:
https://stackoverflow.com/questions/65601383/clean-smaller-objects 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…