static void Main(string[] args) { var EstadoInicial = new AlarmaActivada(); var context = new Alarma(EstadoInicial); EstadoInicial.SetContext(context); Console.WriteLine("-----<Activando alarma>-------"); context.Activar(); Console.WriteLine("-----<Desactivando alarma>----"); Thread.Sleep(2000); context.Desactivar(); Console.WriteLine("-----<Desactivando alarma>----"); Thread.Sleep(2000); context.Desactivar(); Console.WriteLine("-----<Activando alarma>-------"); Thread.Sleep(2000); context.Activar(); Console.ReadKey(); }
static void Main(string[] args) { var EstadoInicial = new Activada(); var context = new Alarma(EstadoInicial); EstadoInicial.SetContext(context); Console.WriteLine("--Activando alarma--"); context.Activar(); Console.ReadKey(); Console.WriteLine("--Desactivando alarma--"); context.Desactivar(); Console.ReadKey(); Console.WriteLine("--Desactivando alarma--"); context.Desactivar(); Console.ReadKey(); Console.WriteLine("--Activando alarma--"); context.Activar(); Console.ReadKey(); }
public void changeState(Alarma Alarmastate) { this.state = Alarmastate; }
public Context(Alarma AlarmaState) { this.state = AlarmaState; state.setContext(this); }