Pattern of the week: Specification Pattern

January 19, 2012 by
Filed under: Architecture, Design, Patterns 

This weeks pattern is the Specification Pattern. We will spend this week reviewing this pattern, how it is used and what its intent is for. For some more in-depth definition you can see here and Here are some useful descriptions, but to appreciate this we will review the intent and possible solutions and applications for this pattern in everyday work.

Here is the intent of the Specification pattern: “ to separate the logic for (e.g.) filtering an entity from the entity itself.”



Example application for this pattern has been to support filtering as a pluggable entity “collection” of specifications.  The implementation details as things mature are apparent with generics and expression tree’s and event the IQueryable<> interfaces against OR/M layers.

The main benefits of this pattern are

1 – Loose coupling of the filter logic from the objects being filtered,

2- Single responsibility: Filtering is essentially a first class citizen and also can exist in a decoupled state for better testing and independent improvement

3 – Composition of specifications allows for reuse and complex nested specifications for easier maintenance.


Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

%d bloggers like this: