15

I don't think I've seen this comparison anywhere, but would they be considered the same? If not, why not?

jzepeda
  • 1,470
  • 2
  • 15
  • 22

2 Answers2

28

They are very similar, but there is a little difference:

  • signals/slots implement the observer pattern, where the producer has a reference to its subscribers and is responsible of notifying them

  • the publish/subscribe paradigm inserts an additional mediator, i.e., the topic handler, which decouples producers and consumers (the producers does not know who will consume messages)

A main consequence is that in the p/s paradigm you can have multiple producers on the same topic.

This is (probably) the most cited article about p/s: The many faces of publish/subscribe

tinito
  • 381
  • 3
  • 3
  • 2
    +1 this is an important technical difference. In practice it means that in a p/s architecture you can replace one or more of the producers without the consumers being affected (because they don't reference the producer directly). This is great for testing consumer logic (replace a producer with a component that "stimulates" the consumers). Similarly, you can add or replace consumers, the producer doesn't care. Great for testing producer logic. – Oliver Jan 16 '14 at 20:34
1

publish subscribe is same as the signals and slots... check this...

http://en.wikipedia.org/wiki/Observer_pattern

http://doc.qt.nokia.com/qtmobility/publish-subscribe.html

shofee
  • 2,079
  • 13
  • 30