Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1021049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:15:08+00:00 2026-05-16T11:15:08+00:00

I’m doing some R&D work, and as such am exploring design patterns. I have

  • 0

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

Consider the following interface contract for a service layer:

public interface IFooDataService
{
   ICollection<Foo> GetFoosBySpecification(Specification<Foo> specification);
   ICollection<Foo> GetFooByPredicate(Func<Foo,bool> predicate);
   ICollection<Foo> GetFooBySearchArgs(FooSearchArgs searchArgs);
}

So, some initial points:

  • All three return a collection of Foo objects
  • All three take one single argument
  • Specification method restricts access to specific requirements
  • Predicate method has basically no restriction
  • Search args method restricts access to specific requirements

Now, onto the implementation:

public ICollection<Foo> GetFoosBySpecification(Specification<Foo> specification)
{
    return fooDataRepository
            .Find()
            .Where(f => specification.IsSatisfiedBy(f))
            .ToList();
}

public ICollection<Foo> GetFooByPredicate(Func<Foo, bool> predicate)
{
    return fooDataRepository
            .Find()
            .Where(predicate)
            .ToList();
}

public ICollection<Foo> GetFooBySearchArgs(FooSearchArgs searchArgs)
{
    return fooDataRepository
            .Find()
            .WhereMeetsSearchCriteria(searchArgs)
            .ToList();
}

Points on the implementation:

  • All three are extremely simple in implementation (one line of chained code)
  • Specification and Search Args filtered implemented externally.
  • Search args method simply uses IEnumerable extension method to inspect args

So, that being said, under what conditions would you use one of above 3 techniques?

My thoughts on Specification Pattern:

  • Nice in that it isolates business/domain requirements into reusable components
  • Extremely easy to read, makes code speak english
  • Fair bit of code involved (interfaces, abstract classes). If i were to use this, i would put the abstractions in a common assembly (so i dont have a bunch of static files in my solution).
  • Easy to change requirements by only changing specification, and not service layer.
  • Supreme testability of domain logic (specifications)

My thoughts on Extension Methods (Pipes & Filters):

  • ‘Weighty’ in logic, but still result in the same simplicity.
  • Isolate query logic from service layer to static methods
  • Still requires “reflection” of sort (inspecting supplied search args and building up query)
  • Allows you to code architecture (repository, service layer) first, without thinking about specific business requirements (which is handy in certain scenarios)

My thoughts on Predicate Method:

  • Could be used where you need coarse grained control over the queries.
  • Good for small projects, where specifications may be overdoing it

My final thought logic is that if you are working on a complex business application where business requirements are known up front but may change over time, then i would use Specification pattern.

But for a application that is a “startup”, ie requirements will evolve over time and has a multitude of ways to retrieve data without complex validation, i would use the Pipes and Filters methods.

What are your thoughts? Have any of you run into problems with any of the above methods? Any recommendations?

About to start a new project so these types of considerations are critical.

Thanks for the help.

EDIT for Clarification on Specification pattern

Here is same usage of the Specification pattern.

Specification<Foo> someSpec; // Specification is an abstract class, implementing ISpecification<TEntity> members (And, Or, Not, IsSatisfiedBy).
someSpec = new AllFoosMustHaveABarSpecification(); // Simple class which inherits from Specification<Foo> class, overriding abstract method "IsSatisfiedBy" - which provides the actual business logic.    
ICollection<Foo> foos = fooDataService.GetFoosBySpecification(someSpec);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:15:09+00:00Added an answer on May 16, 2026 at 11:15 am

    From my little experience :

    1. User requirement always change and i don’t know why my boss always allows that changes to come. So +1 to Specification
    2. Programmer here is more like “manual worker” than “knowledge worker”. You know.. the one who types all day long. By using Specification, i can ensure myself that everybody “types”. This is supported by the nature of my project. It needs many many different implementation for same purpose. Don’t ask me why.
    3. Use a design pattern which gives you highest modularity and flexibility and of course testability. Here’s a little story.
      In a one fine day, my mate told me that he wrote a class which enabled us to calculate 32 kinds of way of calculating X. And he already implemented all that. Hoho, that was such a heroic programming i think. He spent several weeks doing that in the middle of the night. He believed that he was a good programmer so he insisted everybody to use his masterpiece.
      We, at that time, didn’t care about unit testing so we used his masterpiece. What happened then? The code crashed all the time. Well, from that time i realized how important unit test and modularity are.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.