Created
December 24, 2018 07:50
-
-
Save milannankov/b139832aa7ca717b260586a7b15637e0 to your computer and use it in GitHub Desktop.
domain-models-2
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 BankAccount | |
{ | |
public string Id { get; } | |
public Money Balance { get; private set; } | |
public BankAccount(string id, Money balance) | |
{ | |
if(string.IsNullOrEmpty(id)) | |
{ | |
throw new ArgumentNullException(nameof(id)); | |
} | |
this.Id = id; | |
this.Balance = balance; | |
} | |
public void Deposit(Money depositAmount) | |
{ | |
if(!this.Balance.HasSameCurrency(depositAmount)) | |
{ | |
throw new InvalidOperationException("Cannot deposit using different currency.") | |
} | |
this.Balance = this.Balance.Add(depositAmount); | |
} | |
public void Debit(Money debitAmount) | |
{ | |
if (!this.Balance.HasSameCurrency(debitAmount)) | |
{ | |
throw new InvalidOperationException("Cannot debit using different currency."); | |
} | |
this.Balance = this.Balance.Subtract(debitAmount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment