-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from ricemery/BankAccount
Rework interface definition to cleanly show openAccount. Add HINTS.md…
- Loading branch information
Showing
4 changed files
with
31 additions
and
9 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Hints | ||
|
||
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. | ||
|
||
### Common Pitfalls | ||
|
||
In Scala there are two ways to achieve mutable state: Use a "var" or a mutable object. | ||
Two common mistakes here are: | ||
- Do not use a "var" that is also a mutable object. One is enough, but not both together. | ||
- Don't expose the "var" or mutable object to the outside world. So make them "private" and change the mutable object into immutable before you return it as a value. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
trait BankAccount { | ||
|
||
def closeAccount(): Unit | ||
|
||
def getBalance: Option[Int] | ||
|
||
def incrementBalance(increment: Int): Option[Int] | ||
} | ||
|
||
object Bank { | ||
def openAccount(): BankAccount = ??? | ||
} | ||
|
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