示例#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");
 }