Glossary · Automation software engineering and architecture
Observer pattern
Also known as: Observer
German: Beobachtermuster
In software design, the observer pattern is a design pattern in which an object (the subject) keeps a list of dependents (observers) and notifies them automatically when its state changes.
- Software engineering
In one sentence
The observer pattern lets an object notify registered observers automatically whenever its state changes.
Example
The alarm manager registers as an observer of each machine module, so a module notifies it when a fault occurs instead of the manager polling every module.
How it applies
- Engineering: The pattern decouples the subject from the code reacting to it; observers can be added without changing the subject. Notifications must not block the subject, and the order in which observers are notified should not matter.
- PLC software: In cyclic PLC programs the pattern is less common than in event-driven software, but it appears in object-oriented libraries and in HMI and SCADA frameworks.
- Documentation: When a library uses observers, its reference documentation should state when notifications occur, in which task context and whether callbacks may call back into the subject.
Observer vs. publish-subscribe
In the observer pattern, observers register directly with the subject, usually within one program. In the Publish-subscribe pattern, a broker or channel sits between publishers and subscribers, who do not know each other, often across the network.