Sometimes my Aggregate will be very simple; some scenarios are simply not complex enough to require deep trees of objects and relations.
Consider a Website Monitoring application, which periodically pings a URL to check if it is alive.
The Web App will have:
- Id
- FriendlyName
- URL
- IsAlive
It doesn't have much data, doesn't have child objects (except maybe for URL being a Value Object) and will certainly not have much invariants – if any – to enforce either, at least not at this time.
Now some say that because it is not modelling a more complex model, with relationships and internals and whatnot, it is not an Aggregate, it is only an Entity.
The thing is, I don't think that complexity or size should be dictating if it's an Aggregate, Entity or Value Object, but rather its MEANING.
For the Web Application Monitoring domain, that Web App "entity" is the root model, it's what is going to be returned from a Repository. If the domain expert brings new requirements, they will be related to that Web App model.
So, for me, I believe it makes it a WebAppAggregate, rather than a WebAppEntity.
Question: is my line of thinking correct, or did I get it all wrong? Thanks in advance.
Best Answer
The thing is, these terms have definitions spelled out in the blue book
From chapter Five. A Model Expressed in Software
From chapter Six. The Life Cycle of a Domain Object.
It's entirely consistent to have an aggregate that contains only a single entity, that entity having only a single interesting property, and only simple behaviors that change that property from one value to another.
The basic shape is fine: your
WebApp
entity is also the root of the aggregate, which is consistent with the pattern as described by Evans.Raising the domain event in the constructor may be an error; it's certainly a code smell (raising a domain event certainly counts as real work).