Geeks With Blogs
Zackary Geers blog

I'm in JP Boodhoo Nothin' But .Net class, and I when I was told it was a very intense course, they weren't lieing, but I've learned a whole pile of things, I'll try to actually blog on them.  So far my favorite has been the Specification pattern.  With the number of cases we've had at work of "When a new order is created with these items, but not this, unless it does that" type cases, and then we have to put those rules in multiple places, and it's always hard to read...  Using 3.5 with extensions methods, and the Specification Pattern... we could end up with rules like this...

Specification<Order> ordersILike = Orders.That.ContainItemsInCatagory(Catagory.Hats).Or.Orders.That.HaveExpressShipping().Or.Orders.That.AreBeingPaidInCash();

You can then store that specification for later... or combine them with other orders...

Specification<Order> otherOrdersIKindaLike = ordersILike.Or.Orders.That.ContainItemsInCatagory(Catagory.Shoes);

You can then call if(otherOrdersIKindaLike.IsSatisifiedBy(order)) { do something; }  This moves a lot of If conditions off of domain objects and makes it far easier to understand.  JP has videos explaining it on Dot Net Rocks.  It's also techinally beautiful about what you can do with code.

Posted on Thursday, June 26, 2008 11:01 PM | Back to top

Comments on this post: Specifically Specifications

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Zackary Geers | Powered by: