使用领域模型建模关系
Modeling relationships with domain models
在我的系统中,用户可以是团队的成员。
我得到了一个名为 Team 的域模型,其中包含 id
、name
、member_count
和 is_channel
。因此,当我在存储库中获取团队时,我检索了 Team 域模型。
我将如何建模 User 和 Team 之间的关系?因为在谈论关系时,我不关心 Team 模型中的 member_count
和 is_channel
。我什至在 role_type
.
关系中有额外的数据
我应该为名为 TeamScope 的关系创建一个域模型吗?包含 id
、user_id
、team_id
、role_type
?
请参阅我对您使用术语(模型、class、关联)的问题的评论。我假设您在我写回答时滥用了它们。
How would I model the relation between a User
and a Team
? Because when talking about the relation I don’t care about the member_count
and is_channel
from the Team
model (sic). I even have extra data in the relation which is a role_type
.
您可以在领域模型中使用 association class 来表示这一点。
Membership
可以捕捉到role_type
,果然是关联到你想出来的关联
member_count
在开头用 /
表示,表明您将从多重性中得出它的值(它是与团队相关的成员数量的计数)。
您标记了 node.js in your question, so I'm going to point to how to implement association classes in Java(不完全是您的情况,但在 Node.js 中应该很容易应用)。
您几乎肯定应该为一个 TeamMember 对象建模,该对象包含用户的 link、团队的 link 以及用户在该团队中扮演的角色。
团队有一个团队成员列表,用户有一个团队成员列表。团队有一个 MemberCount(不确定这是静态的,还是从 TeamMembers 的数量来看是动态的),我不知道 is_channel 是什么意思...
在我的系统中,用户可以是团队的成员。
我得到了一个名为 Team 的域模型,其中包含 id
、name
、member_count
和 is_channel
。因此,当我在存储库中获取团队时,我检索了 Team 域模型。
我将如何建模 User 和 Team 之间的关系?因为在谈论关系时,我不关心 Team 模型中的 member_count
和 is_channel
。我什至在 role_type
.
我应该为名为 TeamScope 的关系创建一个域模型吗?包含 id
、user_id
、team_id
、role_type
?
请参阅我对您使用术语(模型、class、关联)的问题的评论。我假设您在我写回答时滥用了它们。
How would I model the relation between a
User
and aTeam
? Because when talking about the relation I don’t care about themember_count
andis_channel
from theTeam
model (sic). I even have extra data in the relation which is arole_type
.
您可以在领域模型中使用 association class 来表示这一点。
Membership
可以捕捉到role_type
,果然是关联到你想出来的关联
member_count
在开头用 /
表示,表明您将从多重性中得出它的值(它是与团队相关的成员数量的计数)。
您标记了 node.js in your question, so I'm going to point to how to implement association classes in Java(不完全是您的情况,但在 Node.js 中应该很容易应用)。
您几乎肯定应该为一个 TeamMember 对象建模,该对象包含用户的 link、团队的 link 以及用户在该团队中扮演的角色。
团队有一个团队成员列表,用户有一个团队成员列表。团队有一个 MemberCount(不确定这是静态的,还是从 TeamMembers 的数量来看是动态的),我不知道 is_channel 是什么意思...