I've been using the publish-subscribe pattern for a while for communicating devices and it works really well, making it easy to add extra services without touching the rest. I'm thinking of using it inside an application (think of a monolith or a GUI application).
The basic idea is: every component can subscribe to any event, and can publish events. Every component will keep its own view of the state it needs.
Two additional benefits for this pattern when used on a standalone application:
- I can get a compiler to throw errors when new events are added (using enums etc), making it easier to review whether existent components should be updated when a new event is added.
- Individual components can't crash and miss data (the whole app would crash) making error handling easier too.
What are some examples of this being used (or abandoned)? I have never seen this in apps or libraries. The observer and mediator patterns are more typical.