a demo of observer / pub-sub pattern
make
(if make
command is installed on your machine.)
three observers (subscribers) receive various notifications.
- Many publishers want to send events to their subscribers.
- Subscribers want to subscribe various publishers
- they do not need mutual communication. a publisher always sends messages and a subscriber always receives messages.
- first, read
main.cpp
and see the program's overview. - second, read
publisher.h
andobserver.h
.- They are just interfaces and have no corresponding implementation.
- They exist just to clarify what multiple kinds of observers shoud be able to and what multiple kinds of publishers should be able to.
- (In this program, just only one kind of observers and one kind of publishers are implemented. But usually, the program will have many kinds of those.)
- finally, read anything else.
- I ran this program locally on WSL and worked expectedly.