© Dmitri Nesteruk 2022
D. NesterukDesign Patterns in Modern C++20https://doi.org/10.1007/978-1-4842-7295-4_17

17. Mediator

Dmitri Nesteruk1  
(1)
St. Petersburg, Russia
 

A large proportion of the code we write has different components (classes) that communicate with one another through direct references or pointers. However, there are situations when you don’t want objects to be aware of each other’s presence. Or, perhaps you do want them to be aware of one another, but you still don’t want them to communicate through pointers or references because those can go stale and the last thing you want is to dereference a nullptr.

The Mediator design pattern is a mechanism for facilitating communication between the components. Naturally, the mediator itself ...

Get Design Patterns in Modern C++20: Reusable Approaches for Object-Oriented Software Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.