Gopal
Gopal

Reputation: 265

2 Repositories for Very Similar Entities

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 !!!

Upvotes: 0

Views: 65

Answers (1)

Roy Dictus
Roy Dictus

Reputation: 33149

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.

Upvotes: 1

Related Questions