IT:AD:Patterns:Specification Pattern


Used extensively in 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.

  • 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 ##