Interface DomainEvent

  • All Superinterfaces:
    Producible, ValueObject

    public interface DomainEvent
    extends ValueObject
    A domain event is used to represent something that happened in the domain. It happened in the past and is of interest to the business.

    A domain event always represent something that happened in the past. Its name must be in the past tense and be based upon the ubiquitous language.

    A domain event can be as little as just a name. More often, it will contain values and identifiers that represent the relevant state at the time the event happened. That state should be minimized and the receivers should query the model to access additional information if necessary.

    As they represent something in the past, domain events must be immutable. As such they can only contain immutable objects like value objects, primitive types, strings, etc…

    Domain events are first and foremost about communication, within the system but also with other systems. A domain event should therefore be kept as simple as possible as be easy to serialize.

    Example:

     public class SomeDomainEvent implements DomainEvent {
         private String attribute1;
         private String attribute2;
    
         public SomeDomainEvent(String attribute1, String attribute2) {
             this.attribute1 = attribute1;
             this.attribute2 = attribute2;
         }
    
        @Override
         public int hashCode() {
             // implement based on all attributes
         }
    
        @Override
         public boolean equals() {
             // implement based on all attributes
         }
    
         // Other methods
     }
     
    See Also:
    DomainEventHandler, DomainEventPublisher, DomainEventInterceptor, ValueObject