Skip to content

Latest commit

 

History

History

Observer pattern

Observer pattern specifies how multiple objects (observers) may watch for state changes of some other object (observable).

This pattern is usually implemented using two interfaces: Observable and Observer. Observable interface should at least provide method for Observer subscription, as well as a way to unsubscribe. Observer should provide one or several methods which will be called when Observable state changes. New state can be passed through observers update method, or pulled directly from observable using access properties or methods.

Although, .Net has built in observer support through IObserver and IObservable interfaces, this sample uses its own interfaces to simplify code as much as possible.

Sample content:

  • IObservable and IObserver interfaces
  • Shop class as IObservable implementation
  • Buyer and Shipper classes as IObserver implementations

See usage example in Program.cs.