id;
@NonNull
private List<BankAccountEvent> events;
public BankAccount depositCash(Money money) {
return addBankAccountEvent(id, null, money);
}
public BankAccount withdrawCash(Money money) {
return addBankAccountEvent(null, id, money.negated());
}
public BankAccount depositFrom(BankAccount from, Money money) {
return addBankAccountEvent(id, from.getId(), money);
}
public BankAccount withdrawTo(BankAccount to, Money money) {
return addBankAccountEvent(to.getId(), id, money.negated());
}
public Money getTotalAmount() {
return getTotalAmountByEvents(events);
} private BankAccount addBankAccountEvent(Long toBankAccountId,
Long fromBankAccountId, Money money) {
Long eventId = IdGenerator.generateId();
return addBankAccountEvent(BankAccountEvent.of(eventId, id, null, money));
}
private BankAccount addBankAccountEvent(BankAccountEvent event) {
List<BankAccountEvent> result = Lists.newArrayList(events);
result.add(event);
return of(id, result);
}
} ݱۚೖۚ ݱۚग़ۚ ଞͷޱ࠲ʹग़ۚ ଞͷޱ࠲͔Βೖۚ ೖग़ۚΠϕϯτ͔ΒߴΛฦ͢ ॏཁͳ͜ͱϝιουΛ ϢϏΩλεݴޠʹඥ͚Δ