课程: Programming Foundations: Design Patterns

今天就学习课程吧!

今天就开通帐号,24,100 门业界名师课程任您挑!

The Observer pattern and loose coupling

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…

内容