You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Ashish, I was going through LLD of Traffic Signal System. The design uses observer pattern, but I think that this is slightly misimplemented.
The Code here, i.e. notifyObservers() should not be present in TrafficLight entity.
Rather, it should be called in TrafficController entity, as it has the list of Roads (indirectly TrafficLights) and acts as a subject to infrom all TrafficLights about the signal color update of each of them.
In short, `notifyObservers()` method should be a part of TrafficController and `listenTrafficEvent()/changeColor()` should be part of TrafficLight.
The text was updated successfully, but these errors were encountered:
siddharthmagadum16
changed the title
Traffice Signal System: observer design pattern improper use.
Traffic Signal System: observer design pattern improper usage
Dec 25, 2024
Hi Ashish, I was going through LLD of Traffic Signal System. The design uses observer pattern, but I think that this is slightly misimplemented.
The Code here, i.e.
notifyObservers()
should not be present in TrafficLight entity.Rather, it should be called in TrafficController entity, as it has the list of Roads (indirectly TrafficLights) and acts as a subject to infrom all TrafficLights about the signal color update of each of them.
In short, `notifyObservers()` method should be a part of TrafficController and `listenTrafficEvent()/changeColor()` should be part of TrafficLight.
The text was updated successfully, but these errors were encountered: