Defining Java commands

Each aggregate has one or more command classes. A command contains data from the request. There are no requirements for commands to be serializable, nor, do commands usually need to implement equals() and hashCode() methods.

An aggregate’s command classes must extend an aggregate-specific Command superinterface. That interface/trait must extend the marker interface Command. For example, the AccountCommand trait is the superinterface for all the Account’s commands:

interface AccountCommand extends Command {
}

Concrete Account commands such as OpenAccountCommand implement this interface:

public class OpenAccountCommand implements AccountCommand {

  private BigDecimal initialBalance;

  public OpenAccountCommand(BigDecimal initialBalance) {
    this.initialBalance = initialBalance;
  }

  public BigDecimal getInitialBalance() {
    return initialBalance;
  }
}

Stay in touch
Copyright © 2016 Eventuate, Inc • All rights reserved.