Can an Entity be Shared across many Aggregates?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Can an Entity be Shared across many Aggregates?

justinstuparitz
Can an entity be shared across many aggregates?  In the Blue Book (Evans), in chap 6 on aggregates there is an example of entities Tire and Wheel being used in the aggregate root Car.  If this example was extended to have two aggregates, Car and Truck would it be acceptable to use Tire and Wheel again with Truck?

In the domain I'm currently modeling, there is an entity called Account.  It's a very specific domain type of account.  Right now I have it modeled as an entity in an aggregate root that manages it's life-cycle, but it's used heavily in other aggregate roots as a reference.  It would suggest that what I really need is to make Account an aggregate root in it's own right so I can reference it's ID in other aggregates.  Because from my understanding it's not acceptable to reference an entity's Id or the entity itself outside it's owning aggregate.  What am I missing?

Apologizes for the two part question.
Reply | Threaded
Open this post in threaded view
|

Re: Can an Entity be Shared across many Aggregates?

David Hounslow
I think the example you give of tire and wheel with truck and Car is a
different situation to the one you have with account.

In the Truck and Car example it >might< be acceptable to re-use the tire
and wheel classes as these will be referring to different instances i.e.
A tire an wheel are specific instances tied to either a tire or a truck.
But note what you are not doing here is referring to a sub part of
another aggregate root, i.e. a truck is not referring to a cars tire (or
one car is not referring to another's tire for that matter).

But in the account example it sounds as if you are wanting to refer to
the same account instance in different places. In this case this needs
to be an aggregate root in its own right.

Whether you should you re-use value objects that represent the account
or not is a different issue, but I would caution against it generally
you would only want to refer to the account id in another aggregate, and
a shipping aggregate root might have a different view of the attributes
related to an account to a payment processor for example.

Dave.
Reply | Threaded
Open this post in threaded view
|

Re: Can an Entity be Shared across many Aggregates?

Greg Young
In reply to this post by justinstuparitz
No. The reason why is the aggregate maintains invariants, how would one
aggregate notify the other on change of an entity... If it didn't then you
could possibly have an aggregate in an invalid state.

Yes likely you want it as it's own aggregate with soft links. Btw there is
no problem accessing the id of an entity from outside, the problem is the
same entity being in two aggregates

Greg

On Sunday, November 10, 2013, wrote:

>
>
> Can an entity be shared across many aggregates?  In the Blue Book (Evans),
> in chap 6 on aggregates there is an example of entities Tire and Wheel
> being used in the aggregate root Car.  If this example was extended to have
> two aggregates, Car and Truck would it be acceptable to use Tire and Wheel
> again with Truck?
>
> In the domain I'm currently modeling, there is an entity called Account.
> It's a very specific domain type of account.  Right now I have it modeled
> as an entity in an aggregate root that manages it's life-cycle, but it's
> used heavily in other aggregate roots as a reference.  It would suggest
> that what I really need is to make Account an aggregate root in it's own
> right so I can reference it's ID in other aggregates.  Because from my
> understanding it's not acceptable to reference an entity's Id or the entity
> itself outside it's owning aggregate.  What am I missing?
>
> Apologizes for the two part question.
>  
>


--
Le doute n'est pas une condition agréable, mais la certitude est absurde.
Reply | Threaded
Open this post in threaded view
|

Re: Can an Entity be Shared across many Aggregates?

Rikard Pavelic
In reply to this post by justinstuparitz
On 10.11.2013. 14:57, [hidden email] wrote:
>  
>
> Can an entity be shared across many aggregates?  In the Blue Book (Evans), in chap 6 on aggregates there is an example of entities Tire and Wheel being used in the aggregate root Car.  If this
example was extended to have two aggregates, Car and Truck would it be acceptable to use Tire and Wheel again with Truck?
>
> In the domain I'm currently modeling, there is an entity called Account.  It's a very specific domain type of account.  Right now I have it modeled as an entity in an aggregate root that manages
it's life-cycle, but it's used heavily in other aggregate roots as a reference.  It would suggest that what I really need is to make Account an aggregate root in it's own right so I can reference it's
ID in other aggregates.  Because from my understanding it's not acceptable to reference an entity's Id or the entity itself outside it's owning aggregate.  What am I missing?
>
> Apologizes for the two part question.
>
>
>

While you shouldn't share an entity instance (this would break aggregate boundary),
sharing entity type across multiple aggregates/entities is not a problem (in my book).

Regards,
Rikard

--
Rikard Pavelic
https://dsl-platform.com/

Reply | Threaded
Open this post in threaded view
|

RE: Re: Can an Entity be Shared across many Aggregates?

remyfannader
In reply to this post by David Hounslow
Adding to Dave,
 Those problems can be unambiguously solved by answering two questions:
 1. Does the element have a life-cycle of its own
 2. Is element's use meaningful on its own.
 But answers are contingent on business context: a tire is of no use on its own but can be identified independently, e.g for second use.
 http://caminao.wordpress.com/how-to-implement-symbolic-representations/patterns/functional-patterns/composition-patterns/ http://caminao.wordpress.com/how-to-implement-symbolic-representations/patterns/functional-patterns/composition-patterns/
 http://caminao.wordpress.com/how-to-implement-symbolic-representations/patterns/functional-patterns/connector-patterns/ http://caminao.wordpress.com/how-to-implement-symbolic-representations/patterns/functional-patterns/connector-patterns/
 Remy.


 

---In [hidden email], <david_hounslow@...> wrote:

 I think the example you give of tire and wheel with truck and Car is a
 different situation to the one you have with account.
 
 In the Truck and Car example it >might< be acceptable to re-use the tire
 and wheel classes as these will be referring to different instances i.e.
 A tire an wheel are specific instances tied to either a tire or a truck.
 But note what you are not doing here is referring to a sub part of
 another aggregate root, i.e. a truck is not referring to a cars tire (or
 one car is not referring to another's tire for that matter).
 
 But in the account example it sounds as if you are wanting to refer to
 the same account instance in different places. In this case this needs
 to be an aggregate root in its own right.
 
 Whether you should you re-use value objects that represent the account
 or not is a different issue, but I would caution against it generally
 you would only want to refer to the account id in another aggregate, and
 a shipping aggregate root might have a different view of the attributes
 related to an account to a payment processor for example.
 
 Dave.

Reply | Threaded
Open this post in threaded view
|

RE: Re: Can an Entity be Shared across many Aggregates?

justinstuparitz
In reply to this post by David Hounslow
Thanks everyone.  This makes sense.  It seems the Account entity needs to be modeled as an aggregate with identity links.  

 

 Though now I am confused about the Tire and Wheel example.  I don't know how you would maintain invariants based on object instance across aggregates.  This seems messy and problematic.

 

---In [hidden email], <david_hounslow@...> wrote:

 I think the example you give of tire and wheel with truck and Car is a
 different situation to the one you have with account.
 
 In the Truck and Car example it >might< be acceptable to re-use the tire
 and wheel classes as these will be referring to different instances i.e.
 A tire an wheel are specific instances tied to either a tire or a truck.
 But note what you are not doing here is referring to a sub part of
 another aggregate root, i.e. a truck is not referring to a cars tire (or
 one car is not referring to another's tire for that matter).
 
 But in the account example it sounds as if you are wanting to refer to
 the same account instance in different places. In this case this needs
 to be an aggregate root in its own right.
 
 Whether you should you re-use value objects that represent the account
 or not is a different issue, but I would caution against it generally
 you would only want to refer to the account id in another aggregate, and
 a shipping aggregate root might have a different view of the attributes
 related to an account to a payment processor for example.
 
 Dave.