Be careful when it comes to entities. DDD-Quickly approaches tend to
violate some important concepts regarding entities.
An Entity is something that has an Id.
A value object does NOT have any identifier - a change in any one
property causes it to become a different value object.
An aggregate is a collection on entity and value objects that are
ONLY accessed through an aggregate root.
An aggregate root (AR) is an entity through which the outside world
interacts with an aggregate.
An aggregate is a consistency boundary. All of the aggregate is loaded
and stored together.
Any entity may hold a reference to an AR,
No entity outside of an aggregate may hold a reference to any entity
within the aggregate that is not the AR.
Look at the last three lines again. Be careful about those collections
that "hang off" an aggregate. If you wish to load and save them
independently, then they're no longer part of the aggregate. Nobody
outside an aggregate is allowed to depend on the internal structure of
an aggregate (i.e. what entities it has and how they relate to each
other). All interaction with those "inner" entities are done via
operations on the AR.
In addition, an AR is an entity with a global id. Other entities
within an aggregate have a local id (i.e. an id that's unique only
within the aggregate).
On Oct 26, 6:14 pm, Michael Brown <
mbr...@kharasoft.com> wrote:
> There are four concepts of importance here:
>
> Entity: a unique object within the domain that has significance (e.g. Customer) and can change over time
> Value Object: an immutable object within the domain that has no significance outside of its properties (e.g. date, address)
> Aggregate: a collection of entities or value objects that are related to each other through a root object
> Aggregate Root: An Entity that "owns" an Aggregate and serves as a gateway for all modifications within the Aggregate
>
> From:
ddd...@googlegroups.com [mailto:
ddd...@googlegroups.com] On Behalf Of Sarunas Mazylis
> Sent: Wednesday, October 26, 2011 12:09 PM
> To:
ddd...@googlegroups.com
> Subject: Re: [DDD/CQRS] Difference between Aggregate and Entity
>
> @Colin: Thanks
>
> @All: Is Aggregate an entity? When entity is not an aggregate? Why difference is important?
>
> Thanks
>
> On Wed, Oct 26, 2011 at 7:05 PM, Colin Yates <
colin.ya...@gmail.com<mailto:
colin.ya...@gmail.com>> wrote:
> Entity has meaning (and therefore an id) defined outside of the state of its values as oppose to "value objects" whose identity is defined entirely by its state.
>
> Aggregate a structure of internally consistent and logically related "things" which might be entities or value objects.
>
> (I might be talking nonsense in terms of DDD so believe whoever writes next :))
>