From the course: Spring: Design Patterns

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

The Observer pattern

The Observer pattern

From the course: Spring: Design Patterns

Start my 1-month free trial

The Observer pattern

- The first behavior pattern that we're going to talk about is the observer pattern. Now in Spring there's really one primary use case of the observer pattern, and that is when listening to changes of the ApplicationContext. And you can do that through the ApplicationListener interface that will tell you if and when the ApplicationContext changes. Now this is more of an advanced topic in Spring, and its not that often that you're going to do this. But this is one use case of the observer pattern in the Spring framework. One sort of loose way that the observer pattern is used in the Spring framework is the way JMS, or Rabbit message listeners work. It's a very loose interpretation cause it's really a asynchronous call coming back, but if you look at it logically it is kind of the way that the observer pattern works. So what is this observer pattern? So first and foremost there is an object, that's called a subject. That maintains a list of observers, when a notification is created…

Contents