static void Main(string[] args) { MenuDirector director = new MenuDirector(); //create burger menu MenuBuilder builder1 = new BurgerMenuBuilder(); director.Construct(builder1); Menu menu1 = builder1.GetResult(); Console.WriteLine("Burger menu: {0}", menu1); //create kids menu MenuBuilder builder2 = new KidsMenuBuilder(); director.Construct(builder2); Menu menu2 = builder2.GetResult(); Console.WriteLine("Burger menu: {0}", menu2); //create salad menu MenuBuilder builder3 = new SaladMenuBuilder(); director.Construct(builder3); Menu menu3 = builder3.GetResult(); Console.WriteLine("Burger menu: {0}", menu3); //Result //Burger menu: Burger, Fries, Dessert, Drink //Burger menu: Burger, Fries, Drink, Toy //Burger menu: Salad, Dessert, Drink Console.ReadKey(); }
static void Main(string[] args) { MenuDirector director = new MenuDirector(); MenuBuilder builder1 = new BurgerMenuBuilder(); director.Construct(builder1); Menu menu1 = builder1.GetResult(); Console.WriteLine("Burger menu: {0}", menu1); MenuBuilder builder2 = new KidsMenuBuilder(); director.Construct(builder2); Menu menu2 = builder2.GetResult(); Console.WriteLine("Burger menu: {0}", menu2); MenuBuilder builder3 = new SaladMenuBuilder(); director.Construct(builder3); Menu menu3 = builder3.GetResult(); Console.WriteLine("Burger menu: {0}", menu3); }
//good choice when //seperate construction of complex object from it's representation so you can use the same construction process for diff types of objects //or //parse a complex representation and create one of several target objects out of it. static void Main(string[] args) { //director //builder //concrete builder //product class MenuDirector director = new MenuDirector(); MenuBuilder builder1 = new BurgerMenuBuilder(); director.Contruct(builder1); Menu menu1 = builder1.GetResult(); Console.WriteLine("Burger menu {0}", menu1); }
static void Main(string[] args) { var director = new MenuDirector(); var builder1 = new SaladMenuBuilder(); director.Construct(builder: builder1); var menu = builder1.GetResult(); Console.WriteLine("Salad Menu: {0}", menu); var builder2 = new HamburgerMenuBuilder(); director.Construct(builder2); menu = builder2.GetResult(); Console.WriteLine("Hamburger Menu: {0}", menu); }