Pattern: FluentInterface

Description

Fluent interface allows you do have method chaining

Example in .NET :

FluentInterface


using Microsoft.Extensions.DependencyInjection;
using System.Data;
using System.Data.Common;

namespace FluentInterface;
internal static class FluentInterfaceDemo
{
    public static ServiceCollection AddServices(this ServiceCollection sc)
    {
        //just for demo, does not make sense
        sc
            .AddSingleton<IComparable>((sp) =>
            {
                //does not matter
                return 1970;
            })
            .AddSingleton<IComparable<Int32>>((sp) =>
            {
                //does not matter
                return 16;
            });
        //this way you can chain the calls , making a fluent interface 
        return sc;


    }
}

Learn More

Source Code for Microsoft implementation of FluentInterface

SourceCode Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton

Learn More

Wikipedia

}

Homework

Implement a class person that you can see the first name and last name as fluent interface