域模型 - 标识符关系与层次对象

发布于 2024-07-12 13:37:53 字数 491 浏览 6 评论 0原文

在充实假设的域模型时,我发现自己想知道关联域对象的更好方法是否是让父域对象包含指针(子域对象的标识符),或者使用子对象在父对象内构建组合。

我可以看到每种方法的优缺点,主要是规模与复杂性的权衡,这就是它的归结。 我倾向于更倾向于标识符关系方法,因为我预计不需要进行任何类型的延迟加载。

尽管不直接相关,但域对象是简单的 POCO(POJO 的 .NET 等效项)。 它们被显式标记为可序列化,因为它们最终很可能会在应用程序域之间交叉。 在我看来,LINQ 使关系标识符方法变得可行,如果 LINQ 不可用,我根本不会考虑它。

任何想法将不胜感激!

编辑:还有一些想法可能会让我倾向于仅使用标识符的方法。 首先是对象的缓存策略。 父对象和子对象完全有可能具有不同的 TTL(如其策略所定义)。 第二个是引用持有可能会限制对象重用,因为在可重用数据的情况下,同一个子对象可能由多个父对象持有。 这两者也与序列化对象的整体大小有关。

While fleshing out a hypothetical domain model, I have found myself wondering whether the better approach in relating domain objects would be to have a parent domain object contain a pointer (the identifier of the child) or if it would be a better approach to use the child objects to build a composite within the parent object.

I can see the pros and cons of each approach, mostly a trade off of size versus complexity, being what it boils down to. I would tend to lean more towards a identifier relationship approach, as I am not anticipating the need for doing any sort of lazy loading.

Although not directly related, the domain objects are simple POCOs (.NET-equivalent of POJOs). They are explicitly marked as serializable, as there is a good chance that they will eventually cross between application domains. LINQ makes the relational identifier approach viable, in my opinion, and I would not consider it at all if LINQ were not available.

Any thoughts would be appreciated!

Edit: A couple of more thoughts that might have me lean towards an identifier-only approach. First would be that the caching policy of the objects. It is entirely possible that a parent and child object have different TTLs, as defined by their policies. The second would be that the reference holding might limit object reuse, in that the same child might be held by multiple parents - in the case of reusable data. Both of these also relate to the overall size of the serialized objects, as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七度光 2024-07-19 13:37:53

我在 POCO 上同时使用这两种方法。 我使用父类的子类列表和子类的一个父实例生成它们。

I use both on my POCOs. I generate them with a list of children on the parent class and one parent instance on the child class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文