我有一个问题。我有一个名为 E1 的实体。它有一个 ID 字段。我有另一个实体,E2 是从 E1 派生的。从概念上讲,这两个实体都具有领域意义,因此被明确定义。但唯一的区别是 E2 专门在 ID 上添加了一个“X”。
假设 E1 的 ID 值范围为 (1,2,3,..10)
E2 将具有 1X、5X、6X 等 ID(并非所有 E1 都有专门的 E2),
两者最终本质上映射到同一个表。
我们是否创建 2 个工厂和 2 个存储库来管理这 2 个实体?
如果您能分享您的想法,我将不胜感激!
I have a question. I have an Entity say E1. It is having an ID field. I have another Entity which E2 which is derived from E1. Conceptually both Entities have domain significance and hence explicitly defined. But the only difference is that E2 is specialized with an additional "X" to an ID.
Say E1 has ID values ranging (1,2,3,..10)
E2 will have IDs like 1X,5X,6X etc (not all E1's have specialized E2)
Both finally map essentially to the same table.
Do we create 2 Factories and 2 Repositories to manage these 2 entities?
I appreciate if you can share your ideas !!!
发布评论
评论(1)
如果这两种实体类型实际上是相互独立的——即,ID 为 1 的 E1 实例与 ID 为 2X 的 E2 实例无关——那么它们应该单独管理。尽管很相似,但它们本身就是聚合根,不是吗?
如果它们密切相关——例如在 E2 1X 与 E1 1 相同的情况下,添加一两个属性,那么我真的不知道为什么要单独管理它们。在我看来,E1 根本不应该被管理,E1 的实例必须根据需要在内存中从 E2 的实例创建。
If the two entity types are actually independent of each other -- i.e., an instance of E1 with ID 1 is unrelated to an instance of E2 with ID 2X -- then they should be managed separately. Despite being similar, they are aggregate roots in their own right, aren't they?
If they are strongly related -- such as in the case where E2 1X is the same as E1 1, with one or two properties added, say, then I don't really know why you would manage them separately. It even seems to me that E1 must not be managed at all, and instances of E1 must just be created on an as-needed basis, in memory, from instances of E2.