Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
 public void PressMuteButton(TV context)
 {
     Console.WriteLine("You pressed Mute button. Going from On to Mute mode.");
     tvContext.CurrentState = new Mute(context);
 }
Ejemplo n.º 3
0
 public On(TV context)
 {
     Console.WriteLine("TV is On now.");
     this.tvContext = context;
 }
Ejemplo n.º 4
0
 public void PressOnButton(TV context)
 {
     Console.WriteLine("You pressed On button. TV is already in On state.");
 }
Ejemplo n.º 5
0
 public void PressOffButton(TV context)
 {
     Console.WriteLine("You pressed Off button. Going from On to Off state.");
     tvContext.CurrentState = new Off(context);
 }
Ejemplo n.º 6
0
 public void PressMuteButton(TV context)
 {
     Console.WriteLine("You pressed Mute button. TV is already in Mute mode.");
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 8
0
 public Mute(TV context)
 {
     Console.WriteLine("TV is in Mute mode now.");
     this.tvContext = context;
 }
Ejemplo n.º 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.");
 }
Ejemplo n.º 10
0
 public void PressOffButton(TV context)
 {
     Console.WriteLine("You pressed Off button. TV is already in Off state");
 }