Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Specification Pattern obsolete when you can use Dynamic LINQ?

Wikipedia states that the Specification Pattern is where business logic can be recombined by chaining the business logic together using boolean logic. With respect to selecting filtering objects from lists or collections it seems to me that Dynamic LINQ allows me to accomplish the same thing. Am I missing something? Are there other benefits to the Specification Pattern that should be considered as well?


Edit:

I've found some posts that discuss combining LINQ and the Specification Pattern:

Linq Specifications Project

Implementing the Specification Pattern via Linq by Nicloas Blumhardt (Autofac dude)

Has anyone gone done this road and did it become complicated to maintain?

like image 662
David Robbins Avatar asked Sep 21 '09 11:09

David Robbins


1 Answers

I'm a C# developper and like to use the specification pattern, because it is closer of my business domain. Moreover, you don't have any surprise with this pattern, if a specification class exists, it should work. With Linq, your underlying provider maybe hasn't implemented some features, and you won't know it until runtime.

But definitively, the biggest advantage of specification over linq is to be closer to the business, it's a mini DSL. LINQ for me is a DSL for collection query, not for the business domain.

like image 56
Nicolas Dorier Avatar answered Sep 26 '22 22:09

Nicolas Dorier