vendredi 20 novembre 2020

Is it possible to have multiple subjects in Observer pattern?

I've been working on the Observer pattern, with a one-to-many event. In this case, are multiple classes notified, i.e. more than one observer from one subject? Conversely, could there be more than one subject that I want to ask? Does this situation exceed the Observer pattern and create a different pattern?

Imagine a publishing house that prints newspapers, magazines and books. Users can subscribe to whatever they want. For example, a user might subscribe only to books or to books and newspapers at the same time. Each time a new one of these types is released, the relevant users should be notified. Users who are not registered should not be notified. In other words, if the user is only registered for books, a notification will not be sent for newspapers.

In this example, is the subject the publishing house? Or would books, newspapers, and magazines be separate subjects?

Aucun commentaire:

Enregistrer un commentaire