In order to make my code more organized i have decided to use fluent interfaces; However by reading the available tutorials i have found many ways to implement such fluency, among them i found a topic who says that to create Fluent Interface
we should make use of Interfaces
, but he did not provided any good details in order to achieve it.
Here is how i implement Fluent API
Code
public class Person
{
public string Name { get; private set; }
public int Age { get; private set; }
public static Person CreateNew()
{
return new Person();
}
public Person WithName(string name)
{
Name = name;
return this;
}
public Person WithAge(int age)
{
Age = age;
return this;
}
}
Using The Code
Person person = Person.CreateNew().WithName("John").WithAge(21);
However, how could i involve Interfaces to create Fluent API in a more effective way ?