Member-only story
Easy Python Patterns: The Observer pattern — Code nomad
Introduction
The observer pattern is a software design pattern that allows an object, usually called the subject, to maintain a list of dependents, called observers, and notify them automatically of any state-changes. Many languages have this pattern either built-in or in their standard libraries.
Examples:
- C# has the concept of Observable in the standard .NET library. Also it has the concept of delegates.
- Although Dart doesn’t have it, in Flutter we have the SetState method which automatically notifes any observer, and it is mainly used to refresh the UI.
It looks like this:
A breakdown of this diagram:
- First there is the Observable, this could be an interface, the object which is to be observed. The observable holds a list of observers.
- The Observer, which sends out a message to the observers. This could also be an interface.
- The ConcreteObservable, the concrete class which holds the state. If anything changes in the state, the setState method is called, which in turn…










