DDD - a domain object (aggreagate) with a large collection of another object

In the scenario below

class Group {
    ...
    Set<User> users;
    ...
}

where the number of users is 6 digits, we can safely assume that performing any assembly operation is inefficient directly using any ORM (JPA / Hibernate in Java, maybe you can work with ExtraLazyCollection sleep mode).

To cope with this situation, is it normal that instead of representing the domain relationship between the aggregate and the compiled object as a collection, it can be represented as an operation supported by DomainService, and then by the repository.

class Group {

   User addUser(User anUser, GroupUserService aGroupUserService){ ... }
   void removeUser(User anUser, GroupUserService aGroupUserService){ ... } 
}

class GroupUserService {

   GroupRepository  groupRepository;

   User addUser(User anUser) {
       groupRepository.addUser(anUser);
   }
}

class GroupRepository {

    User addUser(User anUser) {
      //execute the query(JQL or native) to save the user 
    }
}

it sounds like a reasonable decision, without violating the principles of DDD, is there any optimization that is being revised in this case.

+4
1

, GroupMember.

GroupMember member = group.addUser(user);
groupMemberRepository.add(member);

, , " ", , , .

, - , ( , ).

, , , .

, -. - , .

? ? ( )? ?

, , , , , , .

+5

Source: https://habr.com/ru/post/1612745/


All Articles