Implementing the Domain Model
We want to implement the use case of sending money from one account to another. One way to model this in object-oriented fashion is to create an Account entity that allows us to withdraw and deposit money so that we can withdraw money from the source account and deposit it into the target account:
package buckpal.domain;
public class Account {
private AccountId id;
private Money baselineBalance;
private ActivityWindow activityWindow;
// constructors and getters omitted
public Money calculateBalance() {
return Money.add(
this.baselineBalance,
this.activityWindow.calculateBalance(this.id));
}
public boolean withdraw(Money, AccountId targetAccountId) {
if (!mayWithdraw(money)) {
...