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]); }
public void SetState(TrafficLightState state) { _currentState = state; }
public TrafficLight() { _currentState = new RedState(); }