-
Notifications
You must be signed in to change notification settings - Fork 0
Observer Pattern
at-grigorievich edited this page Feb 7, 2022
·
1 revision
Uses a one-to-many relationship. In this regard, there is one suspicious object and many observers. And when an allergy to an object occurs, an alert to all observers automatically occurs.
C# already has a built-in implementation of the pattern using interfaces:IObservable<T> & IObserver<T>
- Сlass that implements an interface
IObservable<T>is called a provider or subject. - Сlass that implements the interface
IObserver<T>is called an observer that receives notifications from the provider. -
IObserver<T>.OnNextmethod that provides the observer with new or current information
Press LMB key to press button and call everyone observers to move to the center.
- All observers move to their points :

- The button is pressed, all observers received a notification and came to the center:
