T
- the aggregate classCT
- the aggregate's command classpublic class ReflectiveMutableCommandProcessingAggregate<T extends ReflectiveMutableCommandProcessingAggregate<T,CT>,CT extends Command> extends java.lang.Object implements CommandProcessingAggregate<T,CT>
Event
,
Here is an example of an aggregate:
public class Account extends ReflectiveMutableCommandProcessingAggregate>Account, AccountCommand< {
private BigDecimal balance;
public BigDecimal getBalance() {
return balance;
}
public List>Event< process(CreateAccountCommand cmd) {
return EventUtil.events(new AccountCreatedEvent(cmd.getInitialBalance()));
}
public void apply(AccountCreatedEvent event) {
this.balance = event.getInitialBalance();
}
public List>Event< process(DebitAccountCommand cmd) {
return EventUtil.events(new AccountDebitedEvent(cmd.getAmount(), cmd.getTransactionId()));
}
public void apply(AccountDebitedEvent event) {
this.balance = this.balance.subtract(event.getAmount());
}
public List>Event< process(NoopAccountCommand cmd) {
return Collections.emptyList();
}
}
Constructor and Description |
---|
ReflectiveMutableCommandProcessingAggregate() |
Modifier and Type | Method and Description |
---|---|
T |
applyEvent(Event event)
Apply an event by invoking an apply() method whose parameter class matches the event's class
|
java.util.List<Event> |
processCommand(CT cmd)
Processes a command by invoking a process() method whose parameter class matches the command's class
|
public ReflectiveMutableCommandProcessingAggregate()
public T applyEvent(Event event)
applyEvent
in interface Aggregate<T extends ReflectiveMutableCommandProcessingAggregate<T,CT>>
event
- the event representing the state changepublic java.util.List<Event> processCommand(CT cmd)
processCommand
in interface CommandProcessingAggregate<T extends ReflectiveMutableCommandProcessingAggregate<T,CT>,CT extends Command>
cmd
- the command to process