The Specification pattern has been added to NGenerics
. In my previous post on the Specification Pattern, we explored creating specification functionality using extension methods. It’s been implemented with the operator methods (And, Or, Xor) on the actual interface, with an abstract class forming the base of all specifications. The deal-breaker for this approach was the need to add operators |, & and ^ to trim down the syntax some. With the Specification Pattern in NGenerics, you can now do this:
Subsumption allows you to compare specifications to see if satisfying one implies satisfaction of the other. It is also sometimes possible to use subsumption to implement satisfaction. If a candidate object can produce a specification that characterizes it, the testing with a specification then becomes a comparison of similar specifications — removing the coupling of specification mechanism entirely from the domain.