The purpose of any kind of messaging pattern in an application is to provide a communication channel between different parts of the code. In object-oriented programming, for instance, this translates to communication between object instances. These patterns are applicable to both mobile and Windows application development. Besides the simplest, One-on-one communication, there are two distinct patterns for communication between object instances that allow multiple subscribers to a particular message or event – the observer pattern and the publish/subscribe pattern. In this video from the recently concluded DelphiCon 2023, Embarcadero MVP Dalija Prasnikar will discuss these respective patterns as well as the NX Horizon event bus and its advantages in Delphi.
What You Should Know about the Observer Pattern and Pub/Sub Patterns?
Generally, the Observer Pattern maintains a close relationship between subjects and observers. It is a relatively easy-to-understand, and widely used messaging design. Here, the Subject maintains a list of observers and whenever there are changes or updates to the subject, it sends a message (event) to its observers about the change. A single subject can emit a variety of events and subscribers can subscribe to observe any particular event. A good example of this pattern is the RSS Feed where a subscriber receives updates whenever new content is published. They can also choose a particular category and be notified of particular changes.
The Pub/Sub Pattern, on the other hand, works quite differently. Unlike the observer pattern, the publish/subscribe pattern keeps a greater distance between publishers and subscribers. Publishers don’t know anything about their subscribers and subscribers don’t know anything about their publishers, they just know which events they are interested in. Here, an event bus serves as a mediator, a communication channel between publishers and subscribers. This is where NX Horizon comes into play.
What does NX Horizon do?
NX Horizon is an open-source event bus, and its primary purpose is to serve as a communication channel in a publish-subscribe pattern. Interestingly, since its instances are lightweight, it can also be used to implement the observer pattern, where each subject will create and hold its own event bus instance. Dalija Prasnikar will walk us through the advantages of NX Horizon in Delphi. One of its notable benefits is that it is thread safe. It is also notably simple with about 700 lines of codes complete with comments. This makes it work fast and easy to use.
Also, one of its core features is the waitable subscription. It also features a specialized DNX Event method that is mainly used for storing event handlers in a subscription. Dalija will also showcase some demos to see NX Horizon in action. The webinar also concludes with a Q&A session with Dalija and Embarcadero MVP Ian Barker where they both address several live questions from the viewers.
To learn more about NX Horizon, feel free to watch the video below.
Design. Code. Kompilieren. Bereitstellen.
Kostenlos testen Upgrade heute
Kostenlose Delphi Community Edition Kostenlose C ++ Builder Community Edition