D
D
driverx182019-06-19 11:35:39
PHP
driverx18, 2019-06-19 11:35:39

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

2 answer(s)
A
Anton, 2019-06-19
@Eridani

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

M
Mysterion, 2019-06-19
@Mysterion

All right. Observer is an observer. It monitors something and receives prompt notifications about changes in the state of the subject. And how he receives notifications and how it is implemented for you is already up to you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question