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 the console. So, we will go ahead and add this.name, the shopper, there is a sale at store name, there is a sale at store name, and then we’ll go ahead and say what the discount is.Discount percent off everything.