Exemplo n.º 1
0
        //implicit state passing - need to pass factory inside, no need for context in state methods


        public static void Main(string[] args)
        {
            var consoleOutput            = new ConsoleOutput();
            var light                    = new DiningRoomLight();
            var lightSwitchStatesFactory = new LightSwitchStatesFactory(light);
            var lightSwitchStateMachine  =
                CreateLightSwitchStateMachine(lightSwitchStatesFactory);

            lightSwitchStateMachine.SwitchOn();
            lightSwitchStateMachine.SwitchOff();
            lightSwitchStateMachine.SwitchOn();
            lightSwitchStateMachine.SwitchOff();
            lightSwitchStateMachine.SwitchOff();
            lightSwitchStateMachine.SwitchOn();
            lightSwitchStateMachine.SwitchOn();
            lightSwitchStateMachine.SwitchOff();
            lightSwitchStateMachine.ShowSwitchesCountOn(consoleOutput);
        }
Exemplo n.º 2
0
 private static SynchronizedLightSwitch CreateLightSwitchStateMachine(
     LightSwitchStatesFactory states)
 {
     return(new SynchronizedLightSwitch(new LightSwitchStateMachine(
                                            states)));
 }