//How do we use all these classes we've just defined? We implement the Client participant! //Let's have our Client ask the user if they are an adult or a child, then display the //corresponding menu items static void Main(string[] args) { Console.WriteLine("Who are you? (A)dult or (C)hild?"); char input = Console.ReadKey().KeyChar; RecipeFactory factory; switch (input) { case 'A': factory = new AdultCuisineFactory(); break; case 'C': factory = new KidCuisineFactory(); break; default: throw new NotImplementedException(); } var sandwich = factory.CreateSandwich(); var dessert = factory.CreateDessert(); Console.WriteLine("\nSandwich: " + sandwich.GetType().Name); Console.WriteLine("Dessert: " + dessert.GetType().Name); Console.ReadKey(); }
static void Main(string[] args) { Console.WriteLine("(A)dult or (C)hild?:"); char input = Console.ReadKey().KeyChar; RecipeFactory factory; switch (input) { case 'A': case 'a': factory = new AdultCuisineFactory(); // aqui se crean el set de objetos break; case 'c': case 'C': factory = new KidCuisineFactory(); break; default: throw new NotImplementedException(); } Console.WriteLine(); Console.WriteLine($"Menu: {factory.GetType().Name}"); Console.WriteLine($"Sandwich: {factory.CreateSandwich().GetType().Name}"); Console.WriteLine($"Dessert: {factory.CreateDessert().GetType().Name}"); }
static void Main(string[] args) { Console.WriteLine("Who are you?"); Console.WriteLine("A- Adult"); Console.WriteLine("K- Kid"); char result = Console.ReadKey().KeyChar; RecipeFactory factory = new AdultCuisineFactory(); switch (result) { case 'A': factory = new AdultCuisineFactory(); break; case 'K': factory = new KidCuisineFactory(); break; default: break; } var burger = factory.CreateBurger(); var dessert = factory.createDessert(); Console.WriteLine(""); Console.WriteLine("Burger: " + burger.GetType().Name); Console.WriteLine("Dessert: " + dessert.GetType().Name); }