An aggregate root is the entity that owns an aggregate’s consistency boundary. It controls state changes so invariants hold across the whole aggregate, including any child entities or collections. Give the root identity and guarded behavior; do not let callers manipulate its state or collections directly. section 9.2.3 section 9.2.5
Use distinct entry points for new and persisted entities:
- Creation validates its inputs and establishes the initial lifecycle state. section 9.2.3
- Reconstitution restores persisted state without revalidating it or raising events; reconcile older data through a separate domain strategy. section 9.2.3
Listing 9.5 Article: The aggregate root, with its two entry points
@Accessors(fluent = true)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@AllArgsConstructor(access = AccessLevel.PRIVATE) #A
public class Article {
@Getter
@EqualsAndHashCode.Include
private final ArticleId id; #B
@Getter
private final Title title;
@Getter
private final Content content;
@Getter
private final AuthorId authorId;
@Getter
private ArticleStatus status; #C
// No getter to avoid direct manipulation of the collection.
private final List<DomainEvent> domainEvents; #D
public static Either<Error, Article>
validateThenCreate(final ArticleId id, final Title title,
final Content content, final AuthorId authorId) {
final List<ValidationError> errors =
new ArrayList<>(); #E
Validations.mandatory(id, "id")
.peekLeft(errors::add);
Validations.mandatory(title, "title")
.peekLeft(errors::add);
Validations.mandatory(content, "content")
.peekLeft(errors::add);
Validations.mandatory(authorId, "authorId")
.peekLeft(errors::add);
return errors.isEmpty()
? Either.right(
new Article(id, title, content, authorId,
ArticleStatus.DRAFT, new ArrayList<>())) #F
: Either.left(new Error.ValidationErrors(List.copyOf(errors)));
}
public static Article reconstitute(final ArticleId id,
final Title title, final Content content,
final AuthorId authorId,
final ArticleStatus status) { #G
return new Article(id, title, content, authorId, status,
new ArrayList<>());
}
// publish(...) and popDomainEvents() follow in listing 9.6
}
Article shows the root’s identity, controlled construction, and separate creation and reconstitution entry points. section 9.2.3
Listing 9.6 Article: The publish transition and the event data
public Either<Error, Article> publish(
final AuthorId requestingAuthor) {
if (this.status != ArticleStatus.DRAFT) { #A
return Either.left(
new Error.BusinessError.ArticleAlreadyPublished(
this.id.value()));
}
if (!this.authorId.equals(requestingAuthor)) { #B
return Either.left(
new Error.BusinessError.AuthorNotAllowedToPublish(
requestingAuthor.value(), this.id.value()));
}
this.status = ArticleStatus.PUBLISHED; #C
this.domainEvents.add(new ArticlePublished( #D
this.id.value(), this.authorId.value(), Instant.now()));
return Either.right(this);
}
public List<DomainEvent> popDomainEvents() {
final List<DomainEvent> popped =
List.copyOf(this.domainEvents); #E
this.domainEvents.clear();
return popped;
}
Publishing checks the current status and requesting author, then changes status and records a domain event. section 9.2.3



