public void Main() { var pb = new PersonBuilder(); Person person = pb .Lives .At("123 London Road") .In("London") .WithPostcode("SW12BC") .Works .At("Fabrikam") .AsA("Engineer") .Earning(123000); Console.WriteLine(person); }
//This method keeps the Open Closed Principle, but I know, It is not really object oriented ;) public void Main() { var pb = new PersonBuilder(); var person = pb.Called("Dmitri").WorksAsA("Programmer").Build(); }
public static PersonBuilder WorksAsA (this PersonBuilder builder, string position) { builder.Actions.Add(p => { p.Position = position; }); return(builder); }