Search the web
Sign In
New User? Sign Up
domaindrivendesign · Domain-Driven Design
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Specification pattern in Repositories?   Message List  
Reply | Forward Message #5312 of 16690 |
There have been several discussions on this list about using
"specifications" to implement the get/find behavior of Repository
classes. I've read Evans/Fowler paper on the Specification pattern a
few times now and I love the idea but I guess I lack imagination when
it comes to implementing it as it's described in the paper in a way
that stays true to the pattern and works for Repositories, which
usually hide a large database.

At its simplest, a Specification is a class that can evaluate any
candidate object and tell us if it satisfies a particular contract:

interface Specification {
public boolean isSatisfiedBy(Object candidate);
}

Trying to solve the Repository.find() problem with a Specification is
tricky because Repositories usually hide large collections of
candidate objects that live in a remote database system. It's simply
not practical to load candidate instances so that your Specification
can pass judgment on each one. You're better off formulating a query
and letting your database hand you the candidates that satisfy your
specification.

This invariably leads to an implementation much different than the
Specification described in the paper by Evans and Fowler and lacking
some of the snazzy features they describe like Composite
Specifications.

I'm curious to know how closely your implementations of Specification
resemble the Specification pattern as described in the Evans/Fowler
paper. My attempts at using the Specification pattern to build find()
methods in Repositories always end up feeling more like Query or
Command object implementations that are distinctly different (and less
useful) than the Specification pattern in the paper. I'm wondering if
I'm missing something.

Here's the Evans/Fowler paper: http://www.martinfowler.com/apsupp/spec.pdf

Any thoughts on this are appreciated.

Hernan,
San Francisco



Thu Apr 26, 2007 7:53 am

hernansilberman
Online Now Online Now
Send Email Send Email

Forward
Message #5312 of 16690 |
Expand Messages Author Sort by Date

There have been several discussions on this list about using "specifications" to implement the get/find behavior of Repository classes. I've read Evans/Fowler...
hernan
hernansilberman
Online Now Send Email
Apr 26, 2007
7:55 am

In .NET 3.5, I am almost wondering if using specifications with a repository is even worth it. I think the ticket may be to use an expression tree...
Tim McCarthy
mccarthyis
Offline Send Email
Apr 28, 2007
3:56 am

... Make no mistake: that's a façade. The thing is this: you have your own class C in your own code. You have also a repository class R. Now, you create a...
Frans Bouma
fransbouma
Offline Send Email
Apr 28, 2007
8:56 am

Yep, this is a decent way to go. We at Mindscape did this on a recent project and I blogged about it here: ...
andrewmindscape
Offline Send Email
May 1, 2007
3:36 am

Yep, this is a good way to go. On our recent BackgroundMotion project for Microsoft this is how we did Repositories. I posted about it on my blog: ...
andrewmindscape
Offline Send Email
May 1, 2007
3:36 am

Hernan, I was just looking into the same problem. In our case we're using NHibernate, which has a Specification-type pattern included already with the...
Pascal Lindelauf
plind69
Offline Send Email
May 21, 2007
12:02 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help