Specification Design Pattern


The central idea of Specification is to separate the statement of how to match a candidate, from the candidate object that it is matched against. The specification responsibility is to identify an object that satisfies it, and to combine with other specifications in various ways that support that basic responsibility (Eric Evans & Martin Fowler)


  • You need to select a subset of objects based on some criteria, and to refresh the selection at various times.
  • You need to check or validate that only suitable objects are used for a certain purpose.


  • Decouple the design of requirements, fulfilment, and validation
  • Allows clear and declarative system definitions


  • There lacks a well-defined purpose for this pattern, and there's no guide when to implement it or not.
  • Separate classes for each part of the specification fragments what could be a cohesive object.

Sample Code

Generic Specification
Gold Customers Specification Sample


    Popular Posts