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

  • SEARCH
  • Home
  • 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 8940283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:59:58+00:00 2026-06-15T10:59:58+00:00

i saw many example of Fluent style api development but some time i saw

  • 0

i saw many example of Fluent style api development but some time i saw people implement fluent with interface and some time people use no interface just use straight forward class. i think people use fluent style api just due to chain of use….means easy access. so i like to know is there any other benefit of fluent api or interns of performance.

here is small code.

public class Coffee
{
    private bool _cream;

    public Coffee Make { get new Coffee(); }

    public Coffee WithCream()
    {
        _cream = true;
        return this;
    }

    public Coffee WithOuncesToServe(int ounces)
    {
        _ounces = ounces;
        return this;
    }
}

var myMorningCoffee = Coffee.Make.WithCream().WithOuncesToServe(16);
  • 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-06-15T10:59:59+00:00Added an answer on June 15, 2026 at 10:59 am

    In your example, I think the syntax (i.e. the “ease of use”) is the only advantage. But for example LINQ methods work differently – the methods don’t return this, they return a new instance. That is obviously a performance hit, but it enables the classes to be immutable, which helps tremendously when you reason about your code, it can promote parallel computations with such classes.

    Edit (example):
    In that case, your Coffee would look like this (although it may not be a good example, because it doesn’t make much sense to me to use fluent syntax here anyway, let alone with new instances)

    public class Coffee
    {
        private bool _cream;
        private int _ounces;
    
        // I really don't like this kind of instantiation,
        // but I kept it there and made static to make it work.
        public static Coffee Make { get new Coffee(); }
    
        public Coffee WithCream()
        {
            return new Coffee
            {
                _cream = true,
                _ounces = this._ounces
            }
        }
    
        public Coffee WithOuncesToServe(int ounces)
        {
            return new Coffee
            {
                _cream = this._cream,
                _ounces = ounces
            };
        }
    

    But of course in case of such a simple class, it is always better to use constructor with parameters, e.g.

    public Coffee(int ounces, bool cream)
    

    And as an opposite example, I remember a set of handy Dictionary extensions for adding items fluently, but without creating a new instance. Something like:

    public static IDictionary<K, V> AddConditionally(
        this IDictionary<K, V> source,
        K key, V value)
    {
        // Real-life implementation would contain more checks etc.
        if(!source.ContainsKey(key))
            source.Add(key, value);
    
        return source;
    }
    

    Which you could use to fill a dictionary with some initial data for example

    var dict = new Dictionary<int, int>()
        .AddConditionally(0,1)
        .AddConditionally(1,1)
        .AddConditionally(2,1)
        .AddConditionally(3,1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this related question about publishing toolchain but I know many people did
I saw many threads with this tittle, but no one really speak about reuse
I saw some websites that (for example): if you want to view your message
I saw many e-commerce sites using Pricegrabber for price comparison. For example: http://www.cheapstingybargains.com/184212/lg-gp08lu10-8x-dvd%C2%B1rw-dl-usb-20-slim-external-drive-w-lightscribe/ Is
I saw in an earlier post here on stackoverflow a example on many to
I saw in a projekt many interfaces which just wrapped a generic class. An
Saw this questions asked many times. But couldn't find a reasonable answer. What is
I'm new to Java. I saw many example about reading XML and when I
I look up a lot through this problem while i saw many post abt
Fastest way to uniqify a list in Python without preserving order? I saw many

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.