public class TrafficLight { private State _state; public TrafficLight() { _state = new GreenState(); } public void ChangeState(State state) { _state = state; } public void Request() { _state.Handle(); } } public abstract class State { public abstract void Handle(); } public class GreenState : State { public override void Handle() { Console.WriteLine("Green Light - Go!"); } } public class YellowState : State { public override void Handle() { Console.WriteLine("Yellow Light - Caution!"); } } public class RedState : State { public override void Handle() { Console.WriteLine("Red Light - Stop!"); } } // Usage example var trafficLight = new TrafficLight(); trafficLight.Request(); // Output: Green Light - Go! trafficLight.ChangeState(new YellowState()); trafficLight.Request(); // Output: Yellow Light - Caution! trafficLight.ChangeState(new RedState()); trafficLight.Request(); // Output: Red Light - Stop!Example 2: Player Movement State Machine ``` public class Player { private readonly StateMachine _stateMachine; public Player() { _stateMachine = new StateMachine(); _stateMachine.Init(new StandingState(this), new JumpingState(this)); } public void HandleInput(string input) { if (input == "jump") { _stateMachine.ChangeState