Definition of Publisher-Subscriber and Observer standards

Asked

Viewed 86 times

0

Today I was evaluating a article (English) concerning the differences between the Observer and Publisher-Subscriber standards, I had until then the view that both were the same thing! Even quoting from itself Wikipedia:

The Observer standard is also called Publisher-Subscriber, Event Generator and Dependents.

In the article the author mentions that this was an interview question, and that he replied that both were equal. The interviewer’s response was that they were NOT equal, according to the article’s definition:

Observer: where there is a change in an object, the "observers" are notified

Publisher-Subscriber: when there is an event, a channel (topic) is notified, and all subscribers of the topic receive the notification. The notifier DOES NOT know his notifiers.

It is confusing because in some places mention that the two patterns are equal and the answer can be considered correct, on the other hand, the difference in implementation shows that they are quite different.

Still, from a conceptual point of view it is correct to say that Publisher-Subscriber is a "derivation" of the Observer pattern and that they are NOT the same thing, or that they are the same thing?

  • 1

    This? https://answall.com/q/36655/101 and this? https://answall.com/q/29046/101

  • @Maniero, I complemented the question better, these two links mention the Observer, but the question would be on how to conceptually consider two patterns, or just the Observer.

1 answer

1


The Observer/Observable standard is mainly implemented in a synchronous manner, i.e., the observable calls the appropriate method of all its observers when an event occurs. In the Publisher/Subscriber standard it is usually implemented asynchronously (using the message queue).

In the Observer/Observable pattern, observers are aware of the observable. Whereas in Publisher/Subscriber, Publishers and subscribers do not need to know each other. They simply communicate with the help of message queues.

In short, they are similar, but there is this subtle difference between them.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.