Author image

Event Queue, Message Bus and Dispatcher


NOTE: I will use the terms event and message interchangeably. In some contexts there may be a minor differentiation but for this discussion it will be ignored.

Event Queue or Message Bus

Definition:

Decouple when a message or event is sent from when it is processed. - R. Nystrom

What's the easiest way to manage the connections between event listeners and event producers? You guessed it “Event Queues”.

When an event occurs, such as user input, or an entity sending an event to another entity, it needs to be stored somewhere such that it's not lost while in transit between the source that reported the event and when the program gets around to respond to it. That “somewhere” is a queue.

New events are added to a queue of unprocessed events. And at a later time when it's convenient in the application we pull off the events from the...

Author image

Observer Design Pattern


Observer is a very important design pattern which is being used in almost every single self-respecting codebase as a way to efficienty communicate between objects in an event-based function. It wouldn't be an understatement to say it is the foundation of event based programming.

Underlying the popular, ever-present in networking, “Model View Controller” (MVC) design pattern, is the observer pattern.

Observers are used in every single game engine - they're known there mostly as “Event dispatchers”. This includes Unreal Engine.

The pattern promotes loose coupling since the Subjects don't need to know anything about the observers.

Alternative terminology for this pattern includes the following: - Subscribe-Publish - Listener-Publisher - Delegate-Model - Sink-Source, where the Subject is the source of events and the Observers are sinks of events

Design

  • a class,...

1