Question

I'm guessing most of us have to deal with this at some point so I thought I'd ask the question.

When you have a lot of collections in your BLL and you find that you're writing the same old inline (anonymous) predicates over and over then there's clearly a case for encapsulation there but what's the best way to achieve that?

The project I'm currently working on takes the age old, answer all, static class approach (E.g User class and static UserPredicates class) but that seems somewhat heavy-handed and a little bit of a cop out.

I'm working in C# mostly so keeping in that context would be most helpful but i think this is generic enough a question to warrant hearing about other languages.

Also I expect there will be a difference in how this might be achieved with the advent of LINQ and Lambdas so I'd be interested in hearing how this could be done in both .Net2.0 and 3.0/3.5 styles.

Thanks in advance.

Was it helpful?

Solution

Specification pattern might be worth checking out.
With some polymorphism & usage of generics it should work.

OTHER TIPS

A Predicate is essentially just an implementation of the Specification design pattern. You can read about the Specification pattern in Domain-Driven Design.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top