Last active
September 11, 2023 17:04
-
-
Save mcsee/55ade1bd7d835ef3804e86b55ec3abaa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Account { | |
private Statement statement; | |
private Amount balance = amountOf(0); | |
public Account(Statement statement) { | |
this.statement = statement; | |
} | |
public void deposit(Amount value, Date date) { | |
recordTransaction(value, date); | |
} | |
public void withdrawal(Amount value, Date date) { | |
recordTransaction(value.negative(), date); | |
} | |
public void printStatement(PrintStream printer) { | |
statement.printTo(printer); | |
} | |
private void recordTransaction(Amount value, Date date) { | |
Transaction transaction = new Transaction(value, date); | |
Amount balanceAfterTransaction = | |
transaction.balanceAfterTransaction(balance); | |
balance = balanceAfterTransaction; | |
statement.addLineContaining(transaction, balanceAfterTransaction); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment