After reading about DDD and Aggregates and taking a look at some StackOverflow posts like this
Update an entity inside an aggregate
Some doubts about aggregates' responsibilities and repositories come to me.
For example, if we supposed that we have user and address entities and one invariant that says that one user should only have a maximum of 3 addresses conforming by this way and Aggregate with those domain rules.
Taking into account this, it is supposed that when you conform that aggregate the access to the addresses child entity inside the user class will be always through user class methods, some methods like this will exist:
user.registerNewContactAddress("street blabl") user.updateContactAddress(address_id,"street blablb") ...
In this basic scenario my questions are:
1) It is supposed that should NOT exist an address repository, but, is it a mandatory rule or discouraged rule in all the cases?
I am thinking about the need to list all the addresses in the system, for example, obviously is more efficient to use an address repository that iterates across all the users and retrieves all their addresses.
Or, for example, an user case that looking for "near" address.
So, maybe an address repository with "only" methods "findAll" and "findXX" fit into DDD philosophy? Leaving the insertion and deletion of addresses managed by user Aggregate watching the invariant?
2) What happens if, for example, instead of having a maximum of 3 addresses we have, 30.000 ( just a stupid case, I know, I'm sorry).
In this case, should we conserve the user.changeAddress(address_id,"street blablb") method ? I guess that it will become a little bit inefficient to retrieve the user and, in memory, iterate across all his addresses, so, it is another case where I see that maybe a direct call to address repository by ID is better.
Thanks