Answer the question
In order to leave comments, you need to log in
Am I right in wanting to use Observer?
Let's say we have an online store. There are goods, each user can "follow the goods", for example, for its discount. Let's take iPhone X 128 GB as an example. Do I understand correctly that he is a Subject, and each person who clicked "follow" him, he becomes his Observer, and when you click on this "follow" button - Subject iPhone X does attach this Observer (user)? In case I understand correctly, where do we store these observers in the database? Separate product table to its observers? And then when the manager changes the price of this product in the admin panel, then we do a notify() of the subject, (under the hood - we select from the database of all the observers of this product and make a notification to them, for example, unsubscribe to the mail about the changed price)
Question: did I understand everything correctly, or is this done in a wrong way at all? Basically the question is where to store all observers, obviously in the database?
Answer the question
In order to leave comments, you need to log in
Yes, in a separate table we will keep the product id, the id or email of the person who is following, and other service fields as needed.
Well, right, we need change events that will trigger the notification process after price changes, etc., in fact, actions after changing the object
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question