Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            TurnstileController controller = new TurnstileController();
            Turnstile           turnstile  = new Turnstile(controller);

            turnstile.HandleEvent(Event.COIN); // Imprime: Desbloqueado!
            turnstile.HandleEvent(Event.PASS); // Imprime: Te bloqueo!
            turnstile.HandleEvent(Event.PASS); // Imprime: ALARMAAAAAAAAAAAA!

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        //En el caso que se quiera agregar transiciones o estados se deben modificar los
        // enumerados y el constructor de Turnstile para haga los nuevos AddTransition
        public Turnstile(TurnstileController controller)
        {
            Action unlockAction   = new Action(controller.Unlock);
            Action thankYouAction = new Action(controller.ThankYou);
            Action alarmAction    = new Action(controller.Alarm);
            Action lockAction     = new Action(controller.Lock);

            AddTransition(State.LOCKED, Event.COIN, State.UNLOCKED, unlockAction);
            AddTransition(State.LOCKED, Event.PASS, State.LOCKED, alarmAction);
            AddTransition(State.UNLOCKED, Event.COIN, State.UNLOCKED, thankYouAction);
            AddTransition(State.UNLOCKED, Event.PASS, State.LOCKED, lockAction);
        }