Observer Pattern

Type

The Observer Design Pattern is a behavioral pattern.

Description

The observer design pattern gives you the ability to trigger an operation in a class (the observer) when the observable class changes its state.

Use

  1. When a class needs to know when a another object its state changes.

Prevent

  1. From the need to implement a polling system (every x minutes, check for changes in object y).

Simple Structure

alt text

Advanced Structure

alt text

References

  1. https://refactoring.guru/design-patterns/observer