Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Chapter 10 - State Pattern:");

            GumballMachine machine = new GumballMachine(10);

            machine.InsertQuarter();
            machine.TurnCrank();
            machine.Dispense();

            machine.SetCount(0);

            machine.InsertQuarter();
            machine.TurnCrank();
            machine.Dispense();

            machine.Refill(10);

            machine.InsertQuarter();
            machine.TurnCrank();
            machine.Dispense();



            Console.ReadKey();
        }
Пример #2
0
 //Method Exclusive to SoldOutState
 public void Refill(int gumballs)
 {
     if (gumballs > 0)
     {
         //Set Machin Gum Balls
         Machine.SetCount(gumballs);
         //Transition State to back in action
         Machine.SetGumballState(Machine.GetNoQuarterState());
     }
 }