Difference Between Pub-Sub Pattern and Observable Pattern
I think this one will be really quick.
Observer Design Pattern
The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. I will give you a real world example. Let’s assume that you are a handsome guy who use dating app and looking for a girl. Then you give your number to the girl you found on the dating app. And there are several other men give their number to that girl. The girl will contacting all of the men who give their number to her and maybe she will ask you to be her boyfriend.
Let’s assume that all of the mens is a collection of observer object. So the above diagram will be same with this:
Publish Subscribe Design Pattern
Publish Subscribe is a messaging pattern where senders of messages, called publishers, do not program the messages to be sent directly to specific receivers, called subscribers, but instead categorize published messages into classes without knowledge of which subscribers, if any, there may be. Similarly, subscribers express interest in one or more classes and only receive messages that are of interest, without knowledge of which publishers, if any, there are.
In other word the publisher and the subscriber will never know about the existence of one another. So how they communicate?
There another component named message broker which is known by both publisher and subscriber. The publisher will send the message to the message broker and the message broker will filtering and broadcasting the message to the right subscriber.
You can read my article about how to create your own pubsub library, just in case you’re interested to know deeper about pubsub pattern.
Again i would say thanks to all my readers and i hope i will comeback with more interesting topic.