Interface AggregateRoot<T>

Type Parameters:
T - the type of the underlying domain object
All Superinterfaces:
Entity<T>
All Known Implementing Classes:
ImmutableAggregateRoot, LazyAggregateRoot, ModifiableAggregateRoot

public interface AggregateRoot<T> extends Entity<T>
Represents the root of an aggregate in a domain model.

An AggregateRoot is a specialized Entity that serves as the entry point for a consistency boundary in domain-driven design.

Unlike nested entities, an AggregateRoot's parent() is always null, as it is the top-level context for its child entities.

previous() can be used to access the prior version of the aggregate, enabling differential processing.

See Also:
  • Method Details

    • parent

      default Entity<?> parent()
      Description copied from interface: Entity
      Retrieves the parent entity of the current entity.
      Specified by:
      parent in interface Entity<T>
      Returns:
      the parent entity of the current entity, or null if this entity does not have a parent
    • lastEventId

      String lastEventId()
      Description copied from interface: Entity
      Retrieves the identifier of the last event applied to the entity hierarchy.
      Specified by:
      lastEventId in interface Entity<T>
      Returns:
      the identifier of the last event as a string, or null if no events have been recorded in the entity's aggregate
    • lastEventIndex

      Long lastEventIndex()
      Description copied from interface: Entity
      Retrieves the index of the last event applied to this entity hierarchy.
      Specified by:
      lastEventIndex in interface Entity<T>
      Returns:
      the index of the last event as a Long, or null if no events have been recorded for the entity's aggregate
    • withEventIndex

      Entity<T> withEventIndex(Long index, String messageId)
      Description copied from interface: Entity
      Updates the event index and message ID of the entity and returns the updated version of the entity.
      Specified by:
      withEventIndex in interface Entity<T>
      Parameters:
      index - the event index to set for the root entity
      messageId - the message ID associated with the event
      Returns:
      the updated entity corresponding to the current entity's ID and type, or null if no such entity can be found
    • sequenceNumber

      long sequenceNumber()
      Description copied from interface: Entity
      Retrieves the sequence number of the current entity.
      Specified by:
      sequenceNumber in interface Entity<T>
      Returns:
      the sequence number of the root entity
    • withSequenceNumber

      Entity<T> withSequenceNumber(long sequenceNumber)
      Description copied from interface: Entity
      Returns an updated entity based on this with the specified sequence number.
      Specified by:
      withSequenceNumber in interface Entity<T>
      Parameters:
      sequenceNumber - the sequence number to assign to the entity
      Returns:
      the updated entity with the specified sequence number, or null if the entity could not be found in the entity hierarchy
    • timestamp

      Instant timestamp()
      Description copied from interface: Entity
      Retrieves the timestamp of the entity.
      Specified by:
      timestamp in interface Entity<T>
      Returns:
      the timestamp as an Instant obtained from the root entity
    • previous

      Entity<T> previous()
      Description copied from interface: Entity
      Retrieves the previous version of this entity.
      Specified by:
      previous in interface Entity<T>
      Returns:
      the previous state of the entity, or null if this is the first known version