Simulate a bank account supporting opening/closing, withdrawals, and deposits of money. Watch out for concurrent transactions!
A bank account can be accessed in multiple ways. Clients can make deposits and withdrawals using the internet, mobile phones, etc. Shops can charge against the account.
Create an account that can be accessed from multiple threads/processes (terminology depends on your programming language).
It should be possible to close an account; operations against a closed account must fail.
This exercise is testing mutable state that can be accessed saftely from multiple threads. Scala provides a variety of ways to protect mutable state. For developers familiar with Java concurrency, Scala can utilize the Java concurrency support such as the Java synchronized block.
In Scala there are two ways to achieve mutable state: Use a "var" or a mutable object. Two common mistakes here are:
Sign up to Exercism to learn and master Scala with 94 exercises, and real human mentoring, all for free.