有聚合根作为属性吗?
聚合根可以有也是聚合根的子项吗?如果是,它是否仅引用它,或者保存另一个聚合根的属性的聚合根是否具有通过该方法更改它的方法?
假设您有一个名为“Worker”的类和另一个名为“Company”的类。两者都是聚合根。公司拥有工人的财产。 很抱歉做了一个坏榜样
public class Company {
private Worker worker;
...
public Worker getWorker() {
...
}
}
public class Worker {
...
}
还是公司类“隐藏”了工人?
public class Company {
private Worker worker;
...
public String getWorkerName() {
...
}
}
public class Worker {
...
}
工人是否只与公司类对话,因为它不是公司上下文的一部分?为什么会这样呢?包含在其他聚合根中的聚合根是否总是像我的第一个示例一样被访问? (我也这么认为,但没有理由)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,不。
这有点难以在 SO 答案中简洁地解释,但这里有一些要点可能有助于您的理解:
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: