Last active
February 25, 2019 13:54
-
-
Save j5ik2o/c344a5ceebe8fa7b7be0e43e66d90b60 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
case class Money(amount: BigDecimal, | |
currency: Currency) { | |
def plus(other: Money): Money = { | |
require(currency == other.currency) | |
new Money(amount = amount.add(other.amount), currency) | |
} | |
} |
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
case class Money(private var _amount: BigDecimal, | |
private var _currency: Currency) { | |
def amount = _amount | |
def currency = _currency | |
def plus(other: Money): Unit = { | |
require(currency == other.currency) | |
amount = amount.add(other.amount) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment