AbstractGets the timestamp when this entity was created.
Gets the timestamp when this entity was last updated.
ProtectedconstructorProtectedrecordProtectedRecords a domain event that occurred within this aggregate. Events are stored internally and can be retrieved later for publishing.
The domain event to record
Retrieves and clears all domain events recorded by this aggregate. This is typically called after the aggregate is persisted, to publish the events.
An array of domain events
Checks if this aggregate has any recorded domain events.
true if there are pending domain events, false otherwise
ProtectedtouchProtectedUpdates the updatedAt timestamp to the current time. Should be called whenever the entity's state changes.
Base class for Aggregate Roots in Domain-Driven Design.
An Aggregate Root is the entry point to an aggregate, which is a cluster of domain objects that can be treated as a single unit. The Aggregate Root ensures the consistency of changes within the aggregate boundary and manages domain events.
Example