Observer Pattern:

The Observer design pattern is a behavioral design pattern that allows an object (called the subject) to automatically notify other objects (called observers) about changes in its state. The subject maintains a list of observers and provides methods to add and remove observers from its list. When a state change occurs, the subject goes through the list and calls a predefined method in each observer. This method usually carries a notification context, such as an event object or simply the new state data. This pattern is quite similar to the Publish-Subscribe (PubSub) pattern. Both are built around the concept of one-to-many relationships where updates from one object are propagated to multiple other objects. However, the difference lies in how these relationships are strucutred and maintained. In the Observer pattern, the subject directly holds referemces to its observers, while in PubSub, a publisher and its subscribers are decoupled by a message broker which manages the subscriptions and event routing. Consider a comic book subscription. You subscribe to this comic (become an observer). Whenever a new issue is published (state change), it's delivered directly to you. Go implementation: