Esempio n. 1
0
        public static TrafficLightState GetLightState <TLightState>() where TLightState : TrafficLightState
        {
            Type type = typeof(TLightState);

            if (!_lightStates.ContainsKey(type))
            {
                lock (_locker)
                {
                    if (!_lightStates.ContainsKey(type))
                    {
                        TrafficLightState typeface = Activator.CreateInstance(typeof(TLightState)) as TrafficLightState;
                        _lightStates.Add(type, typeface);
                    }
                }
            }

            return(_lightStates[type]);
        }
Esempio n. 2
0
 public void SetState(TrafficLightState state)
 {
     _currentState = state;
 }
Esempio n. 3
0
 public TrafficLight()
 {
     _currentState = new RedState();
 }