Created
October 31, 2010 10:09
-
-
Save yreynhout/656386 to your computer and use it in GitHub Desktop.
Guard members
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 Order : Aggregate { | |
public Order Place(Customer customer, ...) { | |
customer.GuardPlaceOrder(); | |
//... | |
} | |
} | |
public class Customer Aggregate { | |
private bool _hasMoreThanFiveOutstandingInvoices; | |
internal void GuardPlaceOrder() { | |
//The kind of rule(s) that go in here might change over time. | |
Guard.Against(_hasMoreThanFiveOutstandingInvoices, PlaceOrderErrorCode.CustomerHasMoreThanFiveOutstandingInvoices); | |
} | |
} | |
public static class Guard { | |
public static void Against<TErrorCode>(bool assertion, TErrorCode errorCode) where TErrorCode : IConvertible { | |
if(assertion) throw new OperationException<TErrorCode>(errorCode); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment