课程: Programming Foundations: Design Patterns
今天就学习课程吧!
今天就开通帐号,24,100 门业界名师课程任您挑!
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…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。