Skip to content

Polymorphic message dispatch

Mogens Heller Grabe edited this page Jan 13, 2021 · 3 revisions

Polymorphic message dispatch consists of doing multiple handler lookups for each incoming message - i.e. for each incoming message, a handler pipeline will be made, consisting of all handlers that handle the specified message including handlers that handle any superclass of the message and handlers that handle an interface implemented by the message.

For example this event:

public class SomeCompositeEvent : ISomethingHappened, ISomethingElseHappened { ... }

that clearly consists of the composition of two discrete events, ISomethingHappened and ISomethingElseHappened. Dispatching SomeCompositeEvent will thus result in dispatching to handlers that implement the following interfaces:

IHandleMessages<SomeCompositeEvent>
IHandleMessages<ISomeHappened>
IHandleMessages<ISomethingElseHappened>
IHandleMessages<object>

Yea, that's right: If a handler implements IHandleMessages<object>, it will get all messages :)

Clone this wiki locally