示例#1
0
    public void DrinkSoda(string input)
    {
        ISoda soda = GetSoda(input);

        soda.Drink();
    }
示例#2
0
 public Consumer(ISoda soda)
 {
     Soda = soda;
 }
示例#3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to the Soda Machine!");
            Console.WriteLine("Would you like Coca Cola sodas or Pepsi Sodas?");
            Console.WriteLine("If you want Coca Cola sodas then press 1");
            Console.WriteLine("If you want Pepsi sodas then press 2");
            ConsoleKeyInfo machineChoice = Console.ReadKey();

            Console.WriteLine(Environment.NewLine);
            ISodaMachine sodaMachine = null;
            ISoda        brand       = null;
            string       sodaName    = String.Empty;

            switch (machineChoice.Key)
            {
            case ConsoleKey.NumPad1:
                sodaMachine = new CocaColaMachine();
                brand       = sodaMachine.LoadSelection();
                DisplaySelection(typeof(CocaColaSelection));
                sodaName = GetSodaChoice(typeof(CocaColaSelection));
                break;

            case ConsoleKey.D1:
                sodaMachine = new CocaColaMachine();
                brand       = sodaMachine.LoadSelection();
                DisplaySelection(typeof(CocaColaSelection));
                sodaName = GetSodaChoice(typeof(CocaColaSelection));
                break;

            case ConsoleKey.NumPad2:
                sodaMachine = new PepsiMachine();
                brand       = sodaMachine.LoadSelection();
                DisplaySelection(typeof(PepsiSelection));
                sodaName = GetSodaChoice(typeof(PepsiSelection));
                break;

            case ConsoleKey.D2:
                sodaMachine = new PepsiMachine();
                brand       = sodaMachine.LoadSelection();
                DisplaySelection(typeof(PepsiSelection));
                sodaName = GetSodaChoice(typeof(PepsiSelection));
                break;

            default:
                Console.WriteLine("No Choice Selected.");
                Console.WriteLine("Closing Program.");
                Environment.Exit(0);
                break;
            }

            Console.WriteLine(Environment.NewLine);
            if (!String.IsNullOrWhiteSpace(sodaName))
            {
                brand.Dispense(sodaName);
            }
            else
            {
                Console.WriteLine("Invalid soda choosen");
            }
            Console.WriteLine("Press any key to exit program.");
            Console.ReadKey();
            Environment.Exit(0);
        }