アプリケーション内のあらゆる種類のメッセージング パターンの目的は、コードのさまざまな部分間の通信チャネルを提供することです。例えば、オブジェクト指向プログラミングでは、これはオブジェクト インスタンス間の通信に変換されます。これらのパターンは、モバイルと Windowsアプリケーション開発の両方に適用できます。最も単純な 1 対 1 の通信の他に、特定のメッセージまたはイベントに対して複数のサブスクライバーを許可するオブジェクト インスタンス間の通信には、オブザーバー パターンとパブリッシュ/サブスクライブ パターンの 2 つの異なるパターンがあります。最近開催された DelphiCon 2023を収録したこのビデオでは、Embarcadero MVP の Dalija Prasnikar が、これらのそれぞれのパターン、NX Horizo​​n イベント バス、および Delphi での利点について説明します。

Observer パターンと Pub/Sub パターンについて知っておくべきこと

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.

NX Horizonの働き

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.


RAD Studio、Delphi、C++Builderを用いれば、開発時間を短縮し、より早く市場に投入可能!
Design. Code. Compile. Deploy.
トライアル版をダウンロードいますぐアップグレード!

Delphi Community Edition(無料)C++Builder Community Edition(無料)