Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Is this a known pattern?

Is this a known pattern?

Scheduled Pinned Locked Moved The Lounge
csharpregexquestion
54 Posts 33 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Nicholas Butler

    I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

    List users = DAL.User.FetchAll( where: user => user.Age > 21 );

    It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

    List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

    Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

    www.NickButler.net

    B Offline
    B Offline
    Brandon Ledbetter
    wrote on last edited by
    #29

    I have been working with a pattern called "composite specification" that uses lambda expressions in this way. We are looking at combining it's use with NHibernate, which can turn the composed lambdas into SQL. Seems like a pretty powerful, flexible approach to me.

    N 1 Reply Last reply
    0
    • N Nicholas Butler

      I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

      List users = DAL.User.FetchAll( where: user => user.Age > 21 );

      It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

      List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

      Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

      www.NickButler.net

      F Offline
      F Offline
      Fabio Franco
      wrote on last edited by
      #30

      How about LOOP? LINQ-Object Oriented Programming

      "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

      1 Reply Last reply
      0
      • N Nicholas Butler

        I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

        List users = DAL.User.FetchAll( where: user => user.Age > 21 );

        It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

        List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

        Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

        www.NickButler.net

        A Offline
        A Offline
        Alessandro Degola
        wrote on last edited by
        #31

        when you use lambda expression and delegates, these are a variant of the observer pattern.

        1 Reply Last reply
        0
        • N Nicholas Butler

          I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

          List users = DAL.User.FetchAll( where: user => user.Age > 21 );

          It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

          List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

          Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

          www.NickButler.net

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #32

          List users = DAL.User.FetchAllUsersOfLegalDrinkingAge(); Then define a static list with all countries and districts with said age. I hate parameters. Edit: (And yes it may be the facade pattern)

          _ 1 Reply Last reply
          0
          • B Baxter R Pearson

            I use this stuff all the time, and love it !! Linq, Lamdas, Linq with Lamdas.. It saves a lot of time with EF.

            N Offline
            N Offline
            Nicholas Butler
            wrote on last edited by
            #33

            Baxter R Pearson wrote:

            It saves a lot of time with EF.

            Exactly :) I've sent you a PM - could you let me know if it doesn't come through ( sometimes they go missing. ) Nick

            www.NickButler.net

            1 Reply Last reply
            0
            • N Nathan Gloyn

              Isn't it just a simple Facade pattern?

              N Offline
              N Offline
              Nicholas Butler
              wrote on last edited by
              #34

              Nathan Gloyn wrote:

              Isn't it just a simple Facade pattern?

              It does hide a lot of complexity, but I think the difference is that the parameters passed are functions not values. I don't know if that makes it a different pattern, though :) Nick

              www.NickButler.net

              N 1 Reply Last reply
              0
              • N Nicholas Butler

                Nathan Gloyn wrote:

                Isn't it just a simple Facade pattern?

                It does hide a lot of complexity, but I think the difference is that the parameters passed are functions not values. I don't know if that makes it a different pattern, though :) Nick

                www.NickButler.net

                N Offline
                N Offline
                Nathan Gloyn
                wrote on last edited by
                #35

                From the all knowing Wikipedia: A facade is an object that provides a simplified interface to a larger body of code, such as a class library. A facade can: - make a software library easier to use, understand and test, since the facade has convenient methods for common tasks; - make the library more readable, for the same reason; Certainly sounds like its a facade based on that definition :)

                1 Reply Last reply
                0
                • N Nicholas Butler

                  I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

                  List users = DAL.User.FetchAll( where: user => user.Age > 21 );

                  It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

                  List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

                  Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

                  www.NickButler.net

                  J Offline
                  J Offline
                  Jonathan C Dickinson
                  wrote on last edited by
                  #36

                  Technically it's a DSL (Domain Specific Language) implemented on top of a formal language. You can tell if it's a DSL if simply reading the words makes approximate sense in English: User fetch all where the user age is greater than 21. You could obviously improve it: Fetch all users where the user age is greater than 21.

                  var users = Fetch.All.Users( where: user => user.Age > 21 );

                  The paradigm you are using is very close to a fluent interface - technically fluent interfaces need to happen with method calls (DAL.Users().Where().Age().GreaterThan(21)) but there isn't any reason you can't violate that - especially if it increases clarity (which yours does).

                  He who asks a question is a fool for five minutes. He who does not ask a question remains a fool forever. [Chineese Proverb] Jonathan C Dickinson (C# Software Engineer)

                  1 Reply Last reply
                  0
                  • B Brandon Ledbetter

                    I have been working with a pattern called "composite specification" that uses lambda expressions in this way. We are looking at combining it's use with NHibernate, which can turn the composed lambdas into SQL. Seems like a pretty powerful, flexible approach to me.

                    N Offline
                    N Offline
                    Nicholas Butler
                    wrote on last edited by
                    #37

                    I've sent you a PM - could let me know if it goes missing? ( they sometimes do ) Nick

                    www.NickButler.net

                    1 Reply Last reply
                    0
                    • N Nicholas Butler

                      I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

                      List users = DAL.User.FetchAll( where: user => user.Age > 21 );

                      It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

                      List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

                      Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

                      www.NickButler.net

                      K Offline
                      K Offline
                      K Quinn
                      wrote on last edited by
                      #38

                      Directed Expression Retrieval Pattern (DERP for short)

                      1 Reply Last reply
                      0
                      • N Nicholas Butler

                        I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

                        List users = DAL.User.FetchAll( where: user => user.Age > 21 );

                        It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

                        List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

                        Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

                        www.NickButler.net

                        L Offline
                        L Offline
                        Leng Vang
                        wrote on last edited by
                        #39

                        Well, it is declarative. It using Linq and lambda. Call it "dLinda". :doh:

                        1 Reply Last reply
                        0
                        • H Henry Minute

                          Suggestion: Predicated Queries/Query

                          Henry Minute Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus! When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is. Cogito ergo thumb - Sucking my thumb helps me to think.

                          I Offline
                          I Offline
                          IAbstract
                          wrote on last edited by
                          #40

                          You can design any method to use a predicate like that. It isn't rocket science - it's LINQ:

                          IEnumerable Fetch(Func predicate){
                          return repository.Where(predicate);
                          }

                          ...as long as you are using the repository that contains type `T`.

                          H 1 Reply Last reply
                          0
                          • N Nicholas Butler

                            I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

                            List users = DAL.User.FetchAll( where: user => user.Age > 21 );

                            It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

                            List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

                            Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

                            www.NickButler.net

                            R Offline
                            R Offline
                            rdalton2100OrSomething
                            wrote on last edited by
                            #41

                            I think that you are talking about basic coding rules that unfortunately most people don't follow or teach or profess often enough, because they get caught up in making sure they separate everything out in to tiers or MVC or MVVP or whatever other bs is popular atm. 1) If you are going to re-use the logic then create a method to centralize the age check, so you don't have the same thing in 2 places. 2) If you are not going to re-use the logic then put it closest to where it will be used. I see people all the time create methods in the BL layer to encapsulate the call to the data layer, because someday another developer will browse through and say, hey...look, I already have a method that does that, and it will save them 5 seconds from having to write it themselves or search to see if it exists elsewhere. Put the logic closest to where it will be used unless you KNOW it is likely to be re-used. There are exceptions if you are working on really big applications, but most apps are small, and the added abstraction makes maintenance a beast. If you want to call it a pattern then please follow the one and only pattern that really matters: Keep It Simple. Abstraction by default is a sign of lack of experience. And those people with 20 years of programming experience on their resume that are itching to post how I got it all wrong (if you are harumphing right now, I mean you). You are idiots that make life difficult for the rest of us. Do us all a favor and go get a job mowing grass or something.

                            Raymond

                            F 1 Reply Last reply
                            0
                            • N Nicholas Butler

                              I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

                              List users = DAL.User.FetchAll( where: user => user.Age > 21 );

                              It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

                              List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

                              Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

                              www.NickButler.net

                              H Offline
                              H Offline
                              Harley L Pebley
                              wrote on last edited by
                              #42

                              Sort of falls along the lines of a "fluent interface."

                              1 Reply Last reply
                              0
                              • I IAbstract

                                You can design any method to use a predicate like that. It isn't rocket science - it's LINQ:

                                IEnumerable Fetch(Func predicate){
                                return repository.Where(predicate);
                                }

                                ...as long as you are using the repository that contains type `T`.

                                H Offline
                                H Offline
                                Henry Minute
                                wrote on last edited by
                                #43

                                I know. I use it every day. I was merely suggesting a name that attempted to describe what the OP was doing. If they had got the hint, they might have opted to modify their Framework/Wrapper/WhateverItWasTheyCalledItICantBeArsedToGoBackAndLook. If I had suggested changes, that would be turning The Lounge into a programming forum, which it ain't. :)

                                Henry Minute Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” I wouldn't let CG touch my Abacus! When you're wrestling a gorilla, you don't stop when you're tired, you stop when the gorilla is. Cogito ergo thumb - Sucking my thumb helps me to think.

                                1 Reply Last reply
                                0
                                • R rdalton2100OrSomething

                                  I think that you are talking about basic coding rules that unfortunately most people don't follow or teach or profess often enough, because they get caught up in making sure they separate everything out in to tiers or MVC or MVVP or whatever other bs is popular atm. 1) If you are going to re-use the logic then create a method to centralize the age check, so you don't have the same thing in 2 places. 2) If you are not going to re-use the logic then put it closest to where it will be used. I see people all the time create methods in the BL layer to encapsulate the call to the data layer, because someday another developer will browse through and say, hey...look, I already have a method that does that, and it will save them 5 seconds from having to write it themselves or search to see if it exists elsewhere. Put the logic closest to where it will be used unless you KNOW it is likely to be re-used. There are exceptions if you are working on really big applications, but most apps are small, and the added abstraction makes maintenance a beast. If you want to call it a pattern then please follow the one and only pattern that really matters: Keep It Simple. Abstraction by default is a sign of lack of experience. And those people with 20 years of programming experience on their resume that are itching to post how I got it all wrong (if you are harumphing right now, I mean you). You are idiots that make life difficult for the rest of us. Do us all a favor and go get a job mowing grass or something.

                                  Raymond

                                  F Offline
                                  F Offline
                                  Fabio Franco
                                  wrote on last edited by
                                  #44

                                  rdalton2100OrSomething wrote:

                                  I see people all the time create methods in the BL layer to encapsulate the call to the data layer

                                  And there goes the independence of the business model, rules and entities. If the business layer becomes dependent on the data layer, then it's not just a business layer. If someday they way to fill the business entities change, this will create a nightmare. You also can't share the business objects between applications that have different data sources. For that we may have a service layer that fill the business layer with data, this way the data layer has no dependency on any layer whatsoever, making it easily consumed by any other layer, architecture or application domain.

                                  "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                                  R 1 Reply Last reply
                                  0
                                  • P peterchen

                                    When you pronounce it quickly, you can make it sound almost like "PEANUT".

                                    FILETIME to time_t
                                    | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

                                    K Offline
                                    K Offline
                                    KP Lee
                                    wrote on last edited by
                                    #45

                                    How about "Pin A Mutt"? Kind of like "Pin the tail...", however I'm thinking along the lines of blindfold, crochet(sp?) needle, and a live dog running around. PETA may have a problem with that. :-D PS When I had a dog, I'd never have volunteered him for this "game".

                                    1 Reply Last reply
                                    0
                                    • N Nicholas Butler

                                      I'm having difficulty finding a name for a style of programming. You can make one up if you like, but I'd prefer something that is already documented :) I've written a layer over the Entity Framework that allows the application code to pass parameters into the data layer that shape the returned result sets. So you can write something like this:

                                      List users = DAL.User.FetchAll( where: user => user.Age > 21 );

                                      It's declarative programming, but I was looking for a more specific name. Something like "locality of intent". Basically, you say what you need in the place where you need it. It's the opposite of having a data layer method like this:

                                      List FetchAllUsersWhereAgeGreaterThan( int minimumAge )

                                      Is this a known pattern? I've run out of obvious words to Google. Ta, Nick

                                      www.NickButler.net

                                      P Offline
                                      P Offline
                                      patbob
                                      wrote on last edited by
                                      #46

                                      Nicholas Butler wrote:

                                      List<User> users = DAL.User.FetchAll( where: user => user.Age > 21 );

                                      This example feels more like a filter to me -- you're accessing the entire list of users filtered through the predicate. So, maybe predicated-filter or predicated-fetch or something like that?

                                      We can program with only 1's, but if all you've got are zeros, you've got nothing.

                                      1 Reply Last reply
                                      0
                                      • P Pete OHanlon

                                        Nicholas Butler wrote:

                                        I just called it caching

                                        Most people do. First law of patterns. They are a fancy name for stuff you already do.

                                        *pre-emptive celebratory nipple tassle jiggle* - Sean Ewington

                                        "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                                        My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                                        L Offline
                                        L Offline
                                        Lost User
                                        wrote on last edited by
                                        #47

                                        Like AJAX, we were doing that "call the server without reloading the page" years before they came up with the name, first using hidden frames, then iFrames and finally XmlHttpRequest!. And Ajax will always remain a cleaning product for me, not a programming thing.

                                        1 Reply Last reply
                                        0
                                        • F Fabio Franco

                                          rdalton2100OrSomething wrote:

                                          I see people all the time create methods in the BL layer to encapsulate the call to the data layer

                                          And there goes the independence of the business model, rules and entities. If the business layer becomes dependent on the data layer, then it's not just a business layer. If someday they way to fill the business entities change, this will create a nightmare. You also can't share the business objects between applications that have different data sources. For that we may have a service layer that fill the business layer with data, this way the data layer has no dependency on any layer whatsoever, making it easily consumed by any other layer, architecture or application domain.

                                          "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson

                                          R Offline
                                          R Offline
                                          rdalton2100OrSomething
                                          wrote on last edited by
                                          #48

                                          If you think that there is a significant chance that the data source provider will be changed then it makes sense to create separation. Most of the time this does not happen. We need to stop teaching people that abstraction is the "right" way to write code. It is not. It is the right way to write some code and solve some problems. It adds needless complexity most of the time. Layers are fine if you really share business objects between applications. I would argue that 90%+ of applications out there do not actually do this, so it just makes the code more difficult to change and maintain.

                                          F 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups