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}"); }
//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(); }