Search code examples
c#.netobservableobserver-pattern

Can a single class be used with the interfaces IObserver and IObservable?


I wonder, can an Observable class be also an Observer? Or it would be a bad practice of the pattern?

I'm programming a pub/sub application and I need to use the Observer pattern to communicate come events between my objects. My question is more of an academic one, whether it would be an option to use the pattern in this way.


Solution

  • Observer: Any object that wishes to be notified when the state of another object changes.

    Observable: Any object whose state may be of interest, and in whom another object may register an interest.

    https://www.infoworld.com/article/2077258/observer-and-observable.html