示例#1
0
        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();
        }
示例#3
0
 public void changeState(Alarma Alarmastate)
 {
     this.state = Alarmastate;
 }
示例#4
0
 public Context(Alarma AlarmaState)
 {
     this.state = AlarmaState;
     state.setContext(this);
 }