# IT:AD:Patterns:Specification Pattern #
* [[../|(UP)]]
{{indexmenu>.#2|nsort tsort}}
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 customers = customerRepository.GetBySpec(IsPremiumCustomerSpecification);
That said, the original MF pattern was written prior to LINQ.
## 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/