Skip to content

Instantly share code, notes, and snippets.

@copypastedeveloper
Created October 10, 2013 04:06
Show Gist options
  • Select an option

  • Save copypastedeveloper/6912899 to your computer and use it in GitHub Desktop.

Select an option

Save copypastedeveloper/6912899 to your computer and use it in GitHub Desktop.
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; }
}
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