No, it is not a duplication question. I have red many sources on the subject, but still I feel like I don't fully understand it.
This is the information I have so far (from multiple sources, be it articles, videos, etc...) about what is an Aggregate and Aggregate Root:
- Aggregate is a collection of multiple Value Objects\Entity references and rules.
- An Aggregate is always a command model (meant to change business state).
- An Aggregate represents a single unit of (database - because essentialy the changes will be persisted) work, meaning it has to be consistent.
- The Aggregate Root is the interface to the external world.
- An Aggregate Root must have a globally unique identifier within the system
- DDD suggests to have a Repository per Aggregate Root
- A simple object from an aggregate can't be changed without its AR(Aggregate Root) knowing it
So with all that in mind, lets get to the part where I get confused:
in this site it says
The Aggregate Root is the interface to the external world. All interaction with an Aggregate is via the Aggregate Root. As such, an Aggregate Root MUST have a globally unique identifier within the system. Other Entites that are present in the Aggregate but are not Aggregate Roots require only a locally unique identifier, that is, an Id that is unique within the Aggregate.
But then, in this example I can see that an Aggregate Root is implemented by a static class called Transfer
that acts as an Aggregate and a static function inside called TransferedRegistered
that acts as an AR.
So the questions are:
- How can it be that the function is an AR, if there must be a globaly unique identifier to it, and there isn't, reason being that its a function. what does have a globaly unique identifier is the Domain Event that this function produces.
- Following question - How does an Aggregate Root looks like in code? is it the event? is it the entity that is returned? is it the function of the Aggregate class itself?
- In the case that the Domain Event that the function returns is the AR (As stated that it has to have that globaly unique identifier), then how can we interact with this Aggregate? the first article clearly stated that all interaction with an Aggregate is by the AR, if the AR is an event, then we can do nothing but react on it.
- Is it right to say that the aggregate has two main jobs:
- Apply the needed changes based on the input it received and rules it knows
- Return the needed data to be persisted from AR and/or need to be raised in a Domain Event from the AR
Please correct me on any of the bullet points in the beginning if some/all of them are wrong is some way or another and feel free to add more of them if I have missed any!
Thanks for clarifying things out!