7. For Example - CQRS Queries View Model UI Queries Commands Publish WS Input Validation Validation Rules View Model Updater DB
8. Common Mistake #2 Assuming that all rules are equally likely to change
9. Rules We Know How To Handle In the domain model only: When a customer cancels an order, if the order was already shipped, charge the customer $$ unless customer is {some status} DB
10. Rules We Struggle With Where to enforce these rules? - First name less than N chars - Username must be unique Not Domain Logic! DB
11. The Domain Model When To Use It & When Not To “If you have complicated and everchanging business rules…” “If you have simple not-null checks and a couple of sums to calculate, a Transaction Script is a better bet” -- Martin Fowler, p119 Patterns of Enterprise Application Architecture
14. What Domain Events Are For What else needs to happen? When a customer cancels an order, if the order was already shipped, charge the customer $$ unless customer is {some status} DomainEvents.Raise<InvokeCancellationFee>( f => f.OrderId = msg.OrderId );
15. Consider The Reverse Going to ship a cancelled order Race condition between command & query “One in a million” failure Let it fail asynchronously Email back to the user “Sorry, that order doesn’t exist anymore”
16. Aggregate Mistakes public class Customer { publicvoidMakePreferred() { foreach(Ordero inthis.UnbilledOrders) o.Discount(10.Percent); } }
17. In Closing Avoid the common mistakes: #1 Layers & tiers #2 Rate of rule change #3 Race Conditions Think about aggregates & bounded contexts
18. Thank you Udi Dahan – The Software Simplist Enterprise Development Expert & SOA Specialist www.UdiDahan.com email@UdiDahan.com
Editor's Notes
Same rules for insurance, finance, retail, online gambling, etc.These are technical constraints.We’d expect domain logic like in the previous slide to change often, these rules hardly ever change.
Thousands of years of paper-based business worked around this just fine, even though the latency increased the chance of these “concurrency conflict”