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. General Programming
  3. C#
  4. What do programmers think about "Fluent Interface's" ?

What do programmers think about "Fluent Interface's" ?

Scheduled Pinned Locked Moved C#
question
13 Posts 6 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.
  • V venomation

    I have researched into "Fluent Interface development", http://en.wikipedia.org/wiki/Fluent_interface[^] and would like to know what the code project community thinks about them... Do people like using them? What scenarios would you use them in? Alternatives? I use them for objects that require too many arguments or optional inputs.

    ICustomerFactory c = new CustomerFluentFactory.Create()
    .WithName("James")
    .WithID();

    S Offline
    S Offline
    Super Lloyd
    wrote on last edited by
    #2

    I have seldom written class along those lines, although the very useful LINQ does! One alternative I like is object initializer: var o = new MyObject {   Name = "foo",   ID = Guid.NewGuid(),   Foo = new Bar   {     Snafu = true,   }, };

    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

    V 1 Reply Last reply
    0
    • S Super Lloyd

      I have seldom written class along those lines, although the very useful LINQ does! One alternative I like is object initializer: var o = new MyObject {   Name = "foo",   ID = Guid.NewGuid(),   Foo = new Bar   {     Snafu = true,   }, };

      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

      V Offline
      V Offline
      venomation
      wrote on last edited by
      #3

      Thank you for the reply! :-D

      1 Reply Last reply
      0
      • V venomation

        I have researched into "Fluent Interface development", http://en.wikipedia.org/wiki/Fluent_interface[^] and would like to know what the code project community thinks about them... Do people like using them? What scenarios would you use them in? Alternatives? I use them for objects that require too many arguments or optional inputs.

        ICustomerFactory c = new CustomerFluentFactory.Create()
        .WithName("James")
        .WithID();

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #4

        I use them for classes where there are logically linked discrete behaviours, such as validation. When you validate a property it is common to check multiple things on it, and a fluent interface is a nice way to do this.

        I'm not a stalker, I just know things. Oh by the way, you're out of milk.

        Forgive your enemies - it messes with their heads

        My blog | My articles | MoXAML PowerToys | Onyx

        V 1 Reply Last reply
        0
        • V venomation

          I have researched into "Fluent Interface development", http://en.wikipedia.org/wiki/Fluent_interface[^] and would like to know what the code project community thinks about them... Do people like using them? What scenarios would you use them in? Alternatives? I use them for objects that require too many arguments or optional inputs.

          ICustomerFactory c = new CustomerFluentFactory.Create()
          .WithName("James")
          .WithID();

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

          venomation wrote:

          What scenarios would you use them in?

          Any place where I want to help someone who is "using" that part of the code. It makes life easier for those who need to work with it, just a good documentation or an example would.

          venomation wrote:

          Alternatives?

          I prefer to implement the Decorator pattern :)

          I are Troll :suss:

          V 1 Reply Last reply
          0
          • P Pete OHanlon

            I use them for classes where there are logically linked discrete behaviours, such as validation. When you validate a property it is common to check multiple things on it, and a fluent interface is a nice way to do this.

            I'm not a stalker, I just know things. Oh by the way, you're out of milk.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Onyx

            V Offline
            V Offline
            venomation
            wrote on last edited by
            #6

            Pete O'Hanlon wrote:

            such as validation

            Thanks for the reply, that's a good idea I may start applying that concept also :D

            1 Reply Last reply
            0
            • L Lost User

              venomation wrote:

              What scenarios would you use them in?

              Any place where I want to help someone who is "using" that part of the code. It makes life easier for those who need to work with it, just a good documentation or an example would.

              venomation wrote:

              Alternatives?

              I prefer to implement the Decorator pattern :)

              I are Troll :suss:

              V Offline
              V Offline
              venomation
              wrote on last edited by
              #7

              Thanks for the comment :D

              Eddy Vluggen wrote:

              I prefer to implement the Decorator pattern :)

              I am familiar with that design pattern, but doesn't that seem more complicated than a simple fluent design? Or is there a way of making a fluent design also a decorator...?

              L 1 Reply Last reply
              0
              • V venomation

                Thanks for the comment :D

                Eddy Vluggen wrote:

                I prefer to implement the Decorator pattern :)

                I am familiar with that design pattern, but doesn't that seem more complicated than a simple fluent design? Or is there a way of making a fluent design also a decorator...?

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

                venomation wrote:

                I am familiar with that design pattern, but doesn't that seem more complicated than a simple fluent design?

                I guess it is. A template of the pattern makes it quite easy to implement, it just takes a bit more time. Might depend on what structures you're most familiair with.

                venomation wrote:

                Or is there a way of making a fluent design also a decorator...?

                Not that I'm aware of.

                I are Troll :suss:

                V 1 Reply Last reply
                0
                • L Lost User

                  venomation wrote:

                  I am familiar with that design pattern, but doesn't that seem more complicated than a simple fluent design?

                  I guess it is. A template of the pattern makes it quite easy to implement, it just takes a bit more time. Might depend on what structures you're most familiair with.

                  venomation wrote:

                  Or is there a way of making a fluent design also a decorator...?

                  Not that I'm aware of.

                  I are Troll :suss:

                  V Offline
                  V Offline
                  venomation
                  wrote on last edited by
                  #9

                  Thanks again!

                  L 1 Reply Last reply
                  0
                  • V venomation

                    Thanks again!

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

                    You're welcome :)

                    1 Reply Last reply
                    0
                    • V venomation

                      I have researched into "Fluent Interface development", http://en.wikipedia.org/wiki/Fluent_interface[^] and would like to know what the code project community thinks about them... Do people like using them? What scenarios would you use them in? Alternatives? I use them for objects that require too many arguments or optional inputs.

                      ICustomerFactory c = new CustomerFluentFactory.Create()
                      .WithName("James")
                      .WithID();

                      J Offline
                      J Offline
                      jschell
                      wrote on last edited by
                      #11

                      venomation wrote:

                      What scenarios would you use them in?

                      I doubt I would ever use them. Especially since the only touted benefit is that it makes it more 'readable' which is a subjective term that one can use to rationalize almost anything.

                      venomation wrote:

                      I use them for objects that require too many arguments or optional inputs.

                      I don't see that your example has "too many arguments" in the first place. But generally something that does in fact have too many arguments might have a design problem. And certainly if one sees a lot of code like that (versus say 1 out of 1000) then it would seem very likely that there are design problems.

                      V 1 Reply Last reply
                      0
                      • V venomation

                        I have researched into "Fluent Interface development", http://en.wikipedia.org/wiki/Fluent_interface[^] and would like to know what the code project community thinks about them... Do people like using them? What scenarios would you use them in? Alternatives? I use them for objects that require too many arguments or optional inputs.

                        ICustomerFactory c = new CustomerFluentFactory.Create()
                        .WithName("James")
                        .WithID();

                        P Offline
                        P Offline
                        PIEBALDconsult
                        wrote on last edited by
                        #12

                        I think it has a needless apostrophe.

                        1 Reply Last reply
                        0
                        • J jschell

                          venomation wrote:

                          What scenarios would you use them in?

                          I doubt I would ever use them. Especially since the only touted benefit is that it makes it more 'readable' which is a subjective term that one can use to rationalize almost anything.

                          venomation wrote:

                          I use them for objects that require too many arguments or optional inputs.

                          I don't see that your example has "too many arguments" in the first place. But generally something that does in fact have too many arguments might have a design problem. And certainly if one sees a lot of code like that (versus say 1 out of 1000) then it would seem very likely that there are design problems.

                          V Offline
                          V Offline
                          venomation
                          wrote on last edited by
                          #13

                          jschell wrote:

                          might have a design problem

                          Thanks for the comment! :laugh:

                          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