예제 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("***State Pattern Demo***\n");
            TV tv = new TV();

            Console.WriteLine("User is pressing buttons in the following sequence:");
            Console.WriteLine("Off->Mute->On->On->Mute->Mute->Off\n");
            tv.PressOffButton();
            tv.PressMuteButton();
            tv.PressOnButton();
            tv.PressOnButton();
            tv.PressMuteButton();
            tv.PressMuteButton();
            tv.PressOffButton();
        }
예제 #2
0
 public void PressMuteButton(TV context)
 {
     Console.WriteLine("You pressed Mute button. Going from On to Mute mode.");
     tvContext.CurrentState = new Mute(context);
 }
예제 #3
0
 public On(TV context)
 {
     Console.WriteLine("TV is On now.");
     this.tvContext = context;
 }
예제 #4
0
 public void PressOnButton(TV context)
 {
     Console.WriteLine("You pressed On button. TV is already in On state.");
 }
예제 #5
0
 public void PressOffButton(TV context)
 {
     Console.WriteLine("You pressed Off button. Going from On to Off state.");
     tvContext.CurrentState = new Off(context);
 }
예제 #6
0
 public void PressMuteButton(TV context)
 {
     Console.WriteLine("You pressed Mute button. TV is already in Mute mode.");
 }
예제 #7
0
 public void PressOnButton(TV context)
 {
     Console.WriteLine("You pressed On button. Going from Mute mode to On state.");
     tvContext.CurrentState = new On(context);
 }
예제 #8
0
 public Mute(TV context)
 {
     Console.WriteLine("TV is in Mute mode now.");
     this.tvContext = context;
 }
예제 #9
0
 public void PressMuteButton(TV context)
 {
     Console.WriteLine("You pressed Mute button. TV is already in Off state, so Mute operation will not work.");
 }
예제 #10
0
 public void PressOffButton(TV context)
 {
     Console.WriteLine("You pressed Off button. TV is already in Off state");
 }