コード例 #1
0
ファイル: Program.cs プロジェクト: dioguima/DesignPatterns
        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();
        }
コード例 #2
0
ファイル: OffState.cs プロジェクト: dioguima/DesignPatterns
 public void DecreaseVelocity(Fan fan)
 {
     Console.WriteLine("The fan is already off");
 }
コード例 #3
0
ファイル: OffState.cs プロジェクト: dioguima/DesignPatterns
 public void IncreaseVelocity(Fan fan)
 {
     fan.currentState = new VelocityOneState();
     Console.WriteLine("Velocity changed: Fan turned on");
 }
コード例 #4
0
 public void DecreaseVelocity(Fan fan)
 {
     fan.currentState = new VelocityOneState();
     Console.WriteLine("Velocity changed: 2 => 1");
 }
コード例 #5
0
 public void IncreaseVelocity(Fan fan)
 {
     Console.WriteLine("It's not possible to increase the velocity anymore");
 }
コード例 #6
0
 public void DecreaseVelocity(Fan fan)
 {
     fan.currentState = new OffState();
     Console.WriteLine("Velocity changed: Fan turned off");
 }
コード例 #7
0
 public void IncreaseVelocity(Fan fan)
 {
     fan.currentState = new VelocityTwoState();
     Console.WriteLine("Velocity changed: 1 => 2");
 }