Design patterns implementation examples

Mediator

Definition:

Defines an object which encapsulates how a set of objects interact with themselves.


Example:

A good example is a Wi-Fi router at home. All electrical devices at home (smartphone, laptop, tablet, printer) do not exchange data directly, but by the router. Laptop -> Router -> Tablet, Tablet -> Router-> Printer and so on. Another example is control tower, airplanes do not communicate directly with themselves but through control tower.


C++ code:

/src/mediator.cpp
Download source code

Mediator UML class diagram:
Mediator UML class diagram

Mediator UML sequence diagram:
Mediator UML sequence diagram