Observer pattern
Also called: Observer, Publish-subscribe, Listener
A design pattern where an object notifies a list of subscribers whenever it changes, without knowing who they are.
Definition
The subject keeps a list of observers (also called listeners or subscribers). Observers subscribe to be told about changes and unsubscribe when they no longer care, and the subject calls each of them when something happens. It is the idea behind click listeners, NotificationCenter, Combine, StateFlow, LiveData and Spring application events. The usual bugs are subscriptions that never end and observers called at the wrong time or on the wrong thread.
In practice
A cart badge subscribes to the cart and updates its number whenever an item is added, while the cart only knows it has observers.