Difference between revisions of "Observer pattern"
Karl Jones (Talk | contribs) |
Karl Jones (Talk | contribs) (→See also) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | The '''observer pattern''' is a [[software design pattern]] in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. | + | The '''observer pattern''' is a [[software design pattern]] in which an object, called the subject, maintains a list of its dependents, called '''observers''', and notifies them automatically of any state changes, usually by calling one of their methods. |
== Description == | == Description == | ||
Line 30: | Line 30: | ||
* [[Lapsed listener problem]] | * [[Lapsed listener problem]] | ||
* [[Model–view–controller]] | * [[Model–view–controller]] | ||
+ | * [[Observable versus promise]] | ||
+ | * [[ReactiveX]] | ||
* [[Software design pattern]] | * [[Software design pattern]] | ||
* [[Zen Cart observer]] | * [[Zen Cart observer]] |
Latest revision as of 07:45, 25 January 2018
The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.
Description
The Observer pattern is mainly used to implement distributed event handling systems.
It is also a key part in the model–view–controller (MVC) architectural pattern.
The observer pattern is implemented in numerous programming libraries and systems, including almost all GUI toolkits.
Memory leaks
The observer pattern can cause memory leaks, known as the lapsed listener problem.
The observer pattern requires both explicit registration and explicit deregistration (as in the dispose pattern), because the subject holds strong references to the observers, keeping them alive.
Leakage can be prevented by the subject holding weak references to the observers.
Related patterns
Related patterns include:
See also
- Lapsed listener problem
- Model–view–controller
- Observable versus promise
- ReactiveX
- Software design pattern
- Zen Cart observer
External links
- Observer pattern @ Wikipedia