specification-pattern

Does using the Specification Pattern truly reduce complexity in your code?

From my reading, it appears that the Specification Pattern can greatly reduce the reduce the number of methods needed to filter data. What benefits have you seen using the Specification Pattern? Were there unforeseen benefits that you noticed. conversely, what pitfalls did you encounter? ...

Implementing a Factory that uses Specifications to determine which type of object to create

This is mainly a thought experiment. So this all is sample code. My goal was to use the specification pattern to eliminate giant blocks of conditional code inside a factory. So with this sample I have a StatusData object that I want to get an implementation of IStatusUpdate that is appropriate for for it. I have the following set of tes...

Specification Pattern for Querying against DataBase using NHibernate

How Do You Implement Specification Pattern for querying database using NHibernate?(without LINQ to NHibernate).I read a lot about Specification Pattern but most of them was about Validation and Querying Memory collection objects. Best method as far as I know using DetachedCriteria in Specification Interface like this. interface ISpeci...

Specification Pattern Example

After reading a series of blogs (here and here) by Chris Missal from LosTechies.com on the Specification Pattern I am am really interested in finding more complete examples. Does anyone know where I could find a more fleshed out example or perhaps an open source project that uses this pattern? ...

Specification Pattern defined in Domain

Using Linq to SQL, and a DDD style Domain Layer with de-coupled repositories, does anyone have any good ideas on how to implement a specification pattern without bleeding L2S concerns up into the domain layer, that is still understandable? :) We have complex business logic surrounding the selection of a set of transaction data, and woul...

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 be...

PHP specification pattern that allows transformation to sql

I'm trying to find out what the best way would be to have a specification pattern in PHP where the specifications could (optionally) by transformed to PHP. I am exploring some new directions and am testing how well they would work. Code and ideas are still very unclear in my mind. Minimal interfaces would be like these: interface IRep...

Specification Pattern vs Specific Hibernate Query

My question is when to use a specification pattern, and when to use specific SQL query. I understood that specific pattern need to collect whole collection and post filter using concrete specification. But i dont't understand the advantage in front of specific SQL query. CarColorSpecification cc = new CarColorSpecification(RED); CarAge...

Repository and Specification pattern

I'm currently setting up a new project, and I have run into a few things, where I need a little input. This is what i'm considering: I would like a generic repository I don't want to return IQueryable from my repository. I would like to encapsulate my queries in specifications. I have implemented the specification pattern It needs to ...

How to adapt the Specification pattern to evaluate a combination of objects ?

I know that the Specification pattern describes how to use a hierarchy of classes implementing ISpecification<T> to evaluate if a candidate object of type T matches a certain specification (= satisfies a business rule). My problem : the business rule I want to implement needs to evaluate several objects (for example, a Customer and a Co...

Building a forms system using DDD

Hi, i'm building a form managment system, thats is, the system will contain many forms, will save them, and perform logic on them, I want to do it using the DDD approach. I want to support easy form layout later on using ASP.NET MVC, so far i see the domain like this: I'll have a base form entity, which should(for now) have a name, fie...

Using the Specification Pattern

Like any design pattern the Specification Pattern is a great concept but susceptible to overuse by an eager architect/developer. I am about to commence development on a new application (.NET & C#) and really like the concept of the Specification Pattern and am keen to make full use of it. However before I go in all guns blazing I would...

good way to implement NotSpecification: isSpecialCaseOf?

I'm implementing the specification pattern. The NotSpecification seems simple at first: NotSpecification.IsSpecialCaseOf(otherSpecification) return !this.specification.isSpecialCaseOf(otherSpecification) But it doesn't work for all Specifications: Not(LesserThan(4)).IsSpecialCaseOf(Equals(5)) This should return false instead of...

Specification Pattern and Boolean Operator Precedence

In our project, we have implemented the Specification Pattern with boolean operators (see DDD p 274), like so: public abstract class Rule { public Rule and(Rule rule) { return new AndRule(this, rule); } public Rule or(Rule rule) { return new OrRule(this, rule); } public Rule not() { return...

Is it ok to call specifications from an aggregate factory for validation, or does that validation call belong in a unit test (DDD)?

I have created a factory and a set of specifications to create and validate an aggregate root. Currently I have some tests for the factory that call the specifications on the product of the factory, but I'm wondering if that's enough. It might be better from a design perspective to couple the factory to the specifications of it's produ...

Need Func to supply to Where() method of both IEnumerable and IQueryable.

I have a Func defined as follows: Func<Foo, bool> IsSuperhero = x => x.WearsUnderpantsOutsideTrousers; I can query IEnumerables like this: IEnumerable<Foo> foos = GetAllMyFoos(); var superFoos = foos.Where(IsSuperhero); But when I try to supply the same Func to the Where method of an IQueryable, I get: 'Cannot convert source type ...

Specification pattern - creating compound specifications using lambdas (C#)

If I have a specification defined as an Expression as below: public Expression<Func<Foo, bool>> IsSuperhuman = x => x.CanFly && x.HasXRayVision; And I want to define another specification 'IsSuperheroine' with the logic 'is superhuman and is female', how can I reuse the existing specification within the new one? ...

Comparison of Specification Pattern, Func<T,bool> Predicates and Pipes & Filters

Hi Guys, I'm doing some R&D work, and as such am exploring design patterns. I have recently been reading up on the Specification pattern and was referred to this great article. I was intrigued by the simplicity and cleanliness of the code, but i started to draw some comparisons to implementing the same cleanliness using other techniq...

Trouble Creating Specification Across Entities With NLinq

I am using the Specification pattern, and have a working implementation (taken from the WhoCanHelpMe Codeplex project) for getting data via NLinq, generic repositories and all that goodness. The root method is: public IList<Case> GetCasesByUsername(string username) { CaseByUserNameSpecification spc = new CaseByUserNameSpecification...

Specification Design Pattern : Writing maintainable Decision Tree type business logic

I was reading the example in this: http://en.wikipedia.org/wiki/Specification_pattern and it seems an interesting pattern. The example can be applied as it is, if the different Specs did not share state or pass on information from one to another. What if each produces some information apart from making the decision that can be reused by...