DDD and Homogeneous Many-to-Many Relationship

后端 未结 3 1647
梦谈多话
梦谈多话 2021-02-06 16:44

Imagine you build a social network. There are users who can add other users as friends. How do you model this in DDD? Naturally you cannot simply have a list of friends in the <

3条回答
  •  难免孤独
    2021-02-06 17:41

    A User could have a list of Friends. A Friend could consist of a UserId, FriendType, GroupId, etc.

    A User could also have a list of FriendRequests. A FriendRequest could have a UserId, RequestMessage, RequestStatus etc.

    User, Friend and FriendRequest could all be part of the same Aggregate. But there could be some duplication by doing so. Another option would be to have one FriendRequest for both users involved, and each user would have a list of received and sent FriendRequest IDs.

    This is just to give you some ideas because in DDD, your design will depend highly about how your app will work, and which features are needed. ;-)

提交回复
热议问题