课程: Node.js: Design Patterns

今天就学习课程吧!

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

Implementing observers

Implementing observers

- [Instructor] In the last lesson, we introduced the observer design pattern. We also showed how we could implement the observer design pattern and have observer objects like shoppers and malls listen to observable objects like the store. In this lesson, we're actually going to write the code to make the observer design pattern work in our example. So, I'm in the exercise files under chapter four, under chapter four lesson nine within the star folder, and we can see that we have the changes that we just made to our index.js file. So, let's go ahead and first make the changes that we need to make to the observers, so I'll start with the shopper. And in order for this to work, the shopper's going to have to implement a method that the store can call. So, we'll call notify, and it will give us the store name and the discount. So, whenever a shopper has been notified of a sale, we'll just go ahead and log that information to…

内容