Decoupling your code using a cross-platform publish/subscribe mechanism
The publish/subscribe pattern, also known as the Observer pattern, is a very popular design pattern. It comes under a lot of different names, but the final scope is always the same alert when something interesting happens to it. In this recipe, we'll see a utilization of the TMessageManager
class, which is the publish/subscribe mechanism implemented in the System.Messaging.pas
unit.
Getting ready...
What exactly does the cross-platform TMessageManager
class do? Put simply, it allows you to listen for events and assign actions to run when those events occur. Just like in VCL or FireMonkey, you know about mouse and keyboard events that occur on certain user interactions. These are very similar, except that we can emit events (or send messages) on our own, when we want to, and not necessarily based on user interaction or other mechanisms inside other components. TMessageManager
is based on the publish/subscribe model because...