without any more theory I will show an example,
Function Sequence
namespace FluentConsoleTestHarness { using System; class Program { static void Main(string[] args) { var areaCalculator = new AreaCalculator(); Console.WriteLine("Total Six Area : {0}", areaCalculator.CalculateSixArea(areaCalculator.CalculateArea(4, 4))); } } public class AreaCalculator { public int CalculateSixArea(int area) { return area * 6; } public int CalculateArea(int height, int width) { return height * width; } } }
Output of the program is as below,
Total Six Area : 96
Press any key to continue . . .
Method Chaining and Fluent Interface
namespace FluentConsoleTestHarness
{ using System; class Program { static void Main(string[] args) { var netSalary = new TaxCalculator().GrossSalary(2222).CalculateSalary(100).TotalNetPay(10); Console.WriteLine("Net Salary {0}", netSalary); } }
public class TaxCalculator { public int Salary { get; set; } public int TaxOffset { get; set; } public int NetPay { get; set; } public TaxCalculator GrossSalary(int salary) { Salary = Salary; return this; } public TaxCalculator CalculateSalary(int taxOffset) { TaxOffset = taxOffset; Salary -= TaxOffset; return this; } public string TotalNetPay(int super) { Salary -= super; return Salary.ToString(); } } }
Output of the program is as below,
Net Salary -110
Press any key to continue . . .
thanks mohammad.
thanks mohammad.