0

Let’s say we have a simple data structure:enter image description here

Both, Interface and Network Printer have EndPoint, which is stored in the different table (with FKs enforced). For example, Interface requires EndPoint’s port numbers be between: 1000-2000 and Network Printer requires port numbers between: 2000-3000. It makes me think that EndPoint can’t be an aggregate root as we don't really need direct access to it and we don’t want directly change endpoint values without knowing its context. Per this post: if something belongs to one aggregate, then other aggregates might refer it as a read-only data. Does mean that EndPoint can’t belong to Interface and Network Printer? Or it still can, as in my case, the same EndPoint instance is never shared between the two aggregates. So Interface and Network Pritner always will be updating its own EndPoint and no consistency violation will happen? Sounds right?

Tenek
  • 437
  • 1
  • 6
  • 15

1 Answers1

3

You haven't explained your domain, but to me an EndPoint doesn't sound like an entity at all and would rather be a value (immutable). Changing the end point would simply consist of replacing the entire old EndPoint value with a new one. Immutable values may be shared across aggregate instances without issues because well, they can't change.

Still, if somehow EndPoint must be an entity then as long as instances are not shared across aggregates it is fine. There is no restrictions on using the same kind of entity in multiple aggregates.

plalx
  • 42,889
  • 6
  • 74
  • 90
  • Thanks, sounds like something still can be represented as ValueObject even it is actually stored in the table with ID field. ID just not exposed on domain level? – Tenek Jun 26 '17 at 21:07
  • @Tenek Can't you simply have the data in the same table? I mean, you can have a dedicated endpoint table even if it's a value, but then from the persistence model perspective it will be an entity and from the model perspective it will be a value (most likely with a hidden ID). – plalx Jun 27 '17 at 01:54
  • Data comes from legacy DB. Right now EndPoint table is referenced from 3 different places, but values are never shared. I will do hidden Id field for domain object or even avoid it at all, as EndPoint can be looked up by repository from its context anyway. Having EndPoint as value object helped me to avoid exposing its repository and simplified whole structure. Thanks for advising! – Tenek Jun 27 '17 at 02:49