Basic Aggregate Question

后端 未结 4 1801
孤独总比滥情好
孤独总比滥情好 2021-01-06 17:57

Is client code allowed to reference entities within an aggregate that is not the root? I have a Story (Root), Team (Entity) and TeamMember

4条回答
  •  佛祖请我去吃肉
    2021-01-06 18:59

    Team should have "has a" relationship with Team member. where as story and team member are not directly related to each other.

    your class should look like:

    class team
    {
    list teamMembers;
    void AddTeamMember(TeamMember member){}
    }
    

    another reason why Team must have add team member method, if the method is part of story then you have to explicitly mention in which team you want to add member.

    addteamMember(Team T, TeamMember member);
    

    Root should provide proper methods to access non root elements(first level of nesting). In your case Team should have addTeamMember method and story should have a method (AddMemberToTeam(team t, teammember m)) which calls addTeamMember method of specified team.

提交回复
热议问题