Exemple #1
0
        static void Main(string[] args)
        {
            string coffeeSelected;

            string[]     condimentsSelected = { };
            CoffeFactory factory            = CoffeFactory.Instance;
            ICoffee      coffee;

            for (; ;)
            {
                ShowCoffeeOpt();                  //Show Coffee Options
                coffeeSelected = ReadCoffeeOpt(); //Reads Coffee Option
                if (string.IsNullOrWhiteSpace(coffeeSelected))
                {
                    break;                                     //Stop program
                }
                ShowCoffeeSelected(coffeeSelected);            //Show selected coffe and if wants condiments
                coffee = factory.CreateCoffee(coffeeSelected); //Creates the selected coffe

                if (Console.ReadKey(true).Key == ConsoleKey.Y) //if Y is pressed
                {
                    ShowCondimentOpt();                        //Show Condiment Options
                    condimentsSelected = ReadCondimentsOpt();  //Read Coffee Option
                }

                coffee = CreateCoffee(factory, coffee, condimentsSelected); //Creates the coffe with the condiments (if there are any)
                ShowCoffeeCreated(coffee);                                  //Shows the created Coffe


                Console.ReadKey();
                Console.Clear();
            }
        }
Exemple #2
0
 static ICoffee CreateCoffee(CoffeFactory factory, ICoffee coffee, string[] condimentsSelected)
 {
     foreach (string condiment in condimentsSelected)
     {
         coffee = factory.AddCondiment(coffee, condiment);                                              //Creates the coffe with the selected condiments
     }
     return(coffee);
 }