Design Patterns: Observer and Publish-Subscribe

Play Design Patterns: Observer and Publish-Subscribe
Sign in to queue


This is the fourth of an eight part series where Robert is joined by Phil Japikse to discuss design patterns. A design pattern is a best practice you can use in your code to solve a common problem.  In this episode, Phil demonstrates the Observer pattern. In this pattern, 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. Phil also compares the Observer pattern to the Publish-Subscribe pattern.





The Discussion

  • User profile image

    Why aren't you using IObserver and IObservable. Is it wrong to implement a Subscribe method that returns an IDisposable like in this example:

  • User profile image

    @Stefan_Tellurian: There's nothing wrong with using IObserver and IObservable, I actually had an example in the talk, but when I flushed it out, I realized that it hid a lot of the pattern, and didn't advance the talk any. So I removed the example since the goal of the talk was to explain the pattern.

  • User profile image

    I really love the series and cant thank enough for the same. This helped me a good understanding on the patterns which initially seemed daunting.

    If I may, can you please make one session on Interface Vs Abstract class, as Robert suggested? In the examples I have seen for the patterns here, Phil is using interfaces but the examples in DoFactory uses Abstract classes. So, I want to understand if this variation will affect pattern in any way.

    Thanks again for this great series

Add Your 2 Cents