tl;dr Mediator ...

Problem

Context

Use Mediator when ...

Solution

Some questions arise out of this:

Implementations

Consequences

A Mediator tends to lead to several consequences:

Variations

A couple of different takes on Mediator include:

Mediator as an Architecture

The mediator topology is useful for events that have multiple steps and require some level of orchestration to process the event. For example, a single event to place a stock trade might require you to first validate the trade, then check the compliance of that stock trade against various compliance rules, assign the trade to a broker, calculate the commission, and finally place the trade with that broker. All of these steps would require some level of orchestration to determine the order of the steps and which ones can be done serially and in parallel. There are two types of events within this pattern: an initial event and a processing event. The initial event is the original event received by the mediator, whereas the processing events are ones that are generated by the mediator and received by the event-processing components.

As an example, consider an insurance company has a client that decides to move. The initial event is a "relocation event". The steps involved in processing a relocation event are contained within an event mediator, and for each initial event step, the event mediator creates a processing event (e.g., change address, recalc quote, etc.), sends that processing event to the event channel and waits for the processing event to be processed by the corresponding event processor (e.g., customer process, quote process, etc.). This process continues until all of the steps in the initial event have been processed.

Last updated: 25 February 2022

Tags: pattern   behavioral   architectural