Created
October 10, 2013 04:06
-
-
Save copypastedeveloper/6912899 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Customer : DomainEntity | |
| { | |
| public decimal AccountBalance { get; private set; } | |
| public IReadOnlyList<Orders> Orders { get { return _orders.ToReadOnlyList();} } | |
| public string Name { get; private set; } | |
| protected Customer() {} | |
| public Customer(string name, decimal openingBalance) | |
| { | |
| if (openingBalance < 0) | |
| throw new NoFreeloadersAllowedException(); | |
| RaiseEvent(new CustomerCreated(name,openingBalance)) | |
| } | |
| public void AddMoney(decimal amountToAdd) | |
| { | |
| RaiseEvent(new CustomerAddedMoney(amountToAdd)) | |
| } | |
| public void PlaceOrder(string iceCreamFlavor, decimal price) | |
| { | |
| if (AccountBalance >= price) | |
| { | |
| AccountBalance-=price; | |
| Orders.Add(new Order { Flavor = iceCreamFlavor }); | |
| return; | |
| } | |
| throw new InsufficientFundsException(); | |
| } | |
| } | |
| public class Order | |
| { | |
| public string Flavor { get; set; } | |
| } |
This file contains hidden or 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 sealed class CustomerCreated | |
| { | |
| public string Name { get; private set;} | |
| public decimal OpeningBalance { get; private set;} | |
| public CustomerCreated(string name, decimal openingBalance) | |
| { | |
| Name = name; | |
| OpeningBalance = openingBalance; | |
| } | |
| } | |
| public sealed class CustomerAddedMoney | |
| { | |
| public decimal Amount { get; private set;} | |
| public CustomerAddedMoney(decimal amount) | |
| { | |
| Amount = amount; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment