Exemplo n.º 1
0
        static void Main(string[] args)
        {
            //Reference: https://sourcemaking.com/design_patterns/state
            string input = "0";
            Fan    fan   = new Fan();

            Console.WriteLine("The fan is turned off please insert the commands");
            while (input.Equals("0") || input.Equals("1"))
            {
                Console.WriteLine("\nPress 0 to decrease the fan velocity or 1 to increase the fan velocity");
                input = Console.ReadLine();

                if (input.Equals("0"))
                {
                    fan.DecreaseVelocity();
                }
                else if (input.Equals("1"))
                {
                    fan.IncreaseVelocity();
                }
            }
            Console.WriteLine("Exiting the application ...");
            Console.Read();
        }
Exemplo n.º 2
0
 public void DecreaseVelocity(Fan fan)
 {
     Console.WriteLine("The fan is already off");
 }
Exemplo n.º 3
0
 public void IncreaseVelocity(Fan fan)
 {
     fan.currentState = new VelocityOneState();
     Console.WriteLine("Velocity changed: Fan turned on");
 }
Exemplo n.º 4
0
 public void DecreaseVelocity(Fan fan)
 {
     fan.currentState = new VelocityOneState();
     Console.WriteLine("Velocity changed: 2 => 1");
 }
Exemplo n.º 5
0
 public void IncreaseVelocity(Fan fan)
 {
     Console.WriteLine("It's not possible to increase the velocity anymore");
 }
Exemplo n.º 6
0
 public void DecreaseVelocity(Fan fan)
 {
     fan.currentState = new OffState();
     Console.WriteLine("Velocity changed: Fan turned off");
 }
Exemplo n.º 7
0
 public void IncreaseVelocity(Fan fan)
 {
     fan.currentState = new VelocityTwoState();
     Console.WriteLine("Velocity changed: 1 => 2");
 }