Differences

This shows you the differences between two versions of the page.

Link to this comparison view

it:ad:patterns:specification_pattern [2019/03/24 12:02] (current)
Line 1: Line 1:
 +# IT:​AD:​Patterns:​Specification Pattern #
  
 +
 +
 +<callout type="​Navigation"​ class="​small">​
 +* [[../​|(UP)]]
 +{{indexmenu>​.#​2|nsort tsort}}
 +
 +
 +</​callout>​
 +
 +
 +<panel title="​Summary">​
 +
 +Used extensively in [[IT/​AD/​Patterns/​DDD/​Components/​App.Domain.Repositories/​]].
 +
 +
 +It's separating ​ the  decision ​ as  to  which object types should be selected in a query from the object that makes the selection.  ​
 +Writing code like this allows reusing a  Domain Layer Specification within a repository as a method for querying:
 +
 +    IEnumerable<​Customer>​ customers = customerRepository.GetBySpec(IsPremiumCustomerSpecification);​
 +
 +That said, the original MF pattern was written prior to LINQ.
 +
 +
 +</​panel>​
 +
 +
 +## Considerations ##
 +
 +
 +
 +* Pros:
 +    * End user can built up and save precompiled Queries. ​
 +        * "​Select all (Invoices with Total > 300.00) AND (Country = GB)"
 +    * We decouple the design of requirements,​ compliance and validation. ​
 +        * ??? EXAMPLE ???
 +    * It allows definition of clear and declarative queries
 +        * Instead of Linq all over the Application Layer, untested until run, Queries can be tested in isolation, and reused.
 +
 +## Recipe ##
 +
 +[TODO]
 +
 +## Resources ##
 +* http://​blog.willbeattie.net/​2011/​02/​specification-pattern-entity-framework.html
 +* http://​nblumhardt.com/​archives/​implementing-the-specification-pattern-via-linq/​
 +* http://​guildsocial.web703.discountasp.net/​dasblogce/​2010/​02/​20/​SpecificationPatternAndLinq.aspx
 +* http://​linqspecs.codeplex.com/​