From the course: Programming Foundations: 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 and loose coupling

The Observer pattern and loose coupling

From the course: Programming Foundations: Design Patterns

Start my 1-month free trial

The Observer pattern and loose coupling

- [Instructor] Let's talk about how the observable pattern helps make our design loosely coupled. We can say that the subjects and observers are loosely coupled because, while they interact, which makes them coupled, they really don't know a lot about each other, which makes them loosely coupled. If you look at the subject, the subject knows only that the observer implements a certain interface. It doesn't need to know the concrete class of the observer. In fact, any class can implement the observable interface and effectively subscribe to the subject. So what about the observer? Well, the subject doesn't know any details of the observer. All the subject knows is that it has a list of objects that implement the observable interface. And it uses that list to notify those observers when something changes. The observers are free to add themselves to the list at any time, they can also remove themselves, or even be replaced by another observer at any time. The subject just doesn't care…

Contents