Sample project on Specification pattern

Today I spent the afternoon building a sample project to demonstrate the power of the Specification pattern. I’m not done yet, but I uploaded sample project on github. This pattern comes particularly handy if you have a lot of search conditions and you’d like to isolate them and make them testable.

About the implementation: ASP.NET MVC 3 running dependency injection on Castle Windsor. I didn’t take the time to include a database so I just created a fake Repository. I used a Façade for abstracting data access away, and there’s a Builder to create the appropriate specification objects based on user input. And user input is aggregated into a query object to enhance loose coupling.

And of course there’s a home-brew implementation of the Specification pattern and the project comes with pretty good test coverage, too. Note that I’d never recommend writing your own implementation, this project is for educational purposes only. In a following post I’ll describe the Good Way™ which I use in work.

The one thing that bothers me with this project is that I had the thought that having interfaces for every class is a nice example of YAGNI, so I only added one when it was absolutely needed. This lead to difficulties in testing and an awkward feeling working with these concrete classes. I guess that I’m yet to find the balance in this question.

So next week I’ll post how the Specification pattern is usable and how to implement it.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s