16.2.2022 |

Mediator Pattern

The Mediator pattern can also be called Controller pattern.

It is a class that sits between different components of your application and helps to decouple them. Components must collaborate indirectly by calling the mediator object.

example UML diagram example from refactoring.guru

An element, triggered by a user, doesn’t communicate with other elements directly, even if it looks like it’s supposed to. Instead, the element only needs to let its mediator know about the event, passing any contextual info along with that notification.

Angular implements the mediator pattern by using its component hierarchy. In its simplest form, a component can communicate with other components via a shared parent component which acts as the mediator:

Angular Mediator Pattern with Parent Component

Injectable Services also often serve for communication between components. In this case, the service is the mediator:

Angular Service


Mediator Pattern

Zur Übersicht

Mehr vom DevSquad...

Dennis Hundertmark

NX Monorepo - Error: ENOENT: no such file or directory

Sven Röttering