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 defined

The Observer pattern defined

From the course: Programming Foundations: Design Patterns

Start my 1-month free trial

The Observer pattern defined

- Thinking about subscribers and publishers is a great way to visualize the observer pattern but if you look at the definition of the observer pattern you'll see something like this. The observer pattern defines a one-to-many dependency between objects so that when one object changes state, all its dependents are notified and updated automatically. Let's step through what that means. First, the definition says that the observer pattern defines a one-to-many relationship between a set of objects. We often call these objects the subject and the dependent, which is analogous to publisher and subscriber in our example and we call it a one-to-many because if the state changes in the subject, then the many dependents are notified of that state change. All dependent means here is that these objects are dependent on the subject for data. We often call the dependent the subscriber or more commonly the observer. The subject owns the data in the sense that there's only one copy of it and by…

Contents