Can aggregate roots have childs which also is aggregate roots? If yes, does it only reference it or does the aggregate root that holds a property of the other aggregate root have methods that changes it through that method?
Let say you have a class named “Worker” and another named “Company”. Both are aggregate roots. Company have a property of Worker. Sorry for making a bad example
public class Company {
private Worker worker;
...
public Worker getWorker() {
...
}
}
public class Worker {
...
}
or does the company class “hide” the worker?
public class Company {
private Worker worker;
...
public String getWorkerName() {
...
}
}
public class Worker {
...
}
And does worker talk only to the company class because it is not part of the company context? Why so? Are aggregate roots contained inside other aggregate roots always accessed like my first example? (I would think so, but I have no reason why)
In short, no.
This is kinda tough to explain succinctly in a SO answer, but here’s a few bullet points that may help your understanding: