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(); }
public void PressMuteButton(TV context) { Console.WriteLine("You pressed Mute button. Going from On to Mute mode."); tvContext.CurrentState = new Mute(context); }
public On(TV context) { Console.WriteLine("TV is On now."); this.tvContext = context; }
public void PressOnButton(TV context) { Console.WriteLine("You pressed On button. TV is already in On state."); }
public void PressOffButton(TV context) { Console.WriteLine("You pressed Off button. Going from On to Off state."); tvContext.CurrentState = new Off(context); }
public void PressMuteButton(TV context) { Console.WriteLine("You pressed Mute button. TV is already in Mute mode."); }
public void PressOnButton(TV context) { Console.WriteLine("You pressed On button. Going from Mute mode to On state."); tvContext.CurrentState = new On(context); }
public Mute(TV context) { Console.WriteLine("TV is in Mute mode now."); this.tvContext = context; }
public void PressMuteButton(TV context) { Console.WriteLine("You pressed Mute button. TV is already in Off state, so Mute operation will not work."); }
public void PressOffButton(TV context) { Console.WriteLine("You pressed Off button. TV is already in Off state"); }