Mediator Design Pattern

Video Lecture

Mediator Design Pattern Mediator Design Pattern


The mediator pattern is a behavioural pattern that defines an object that encapsulates how a set of objects interact.

With the mediator pattern, communication between objects is encapsulated within a mediator object.

Objects communicate through the mediator rather than directly with each other.

Mediator Pattern UML Diagram

Source Code

from abc import ABCMeta, abstractmethod

class IComponent(metaclass=ABCMeta):
    def notify(msg):
        """The required notify method"""

    def receive(msg):
        """The required receive method"""

class Component(IComponent):
    def __init__(self, mediator, name):
        self.mediator = mediator = name

    def notify(self, message):
        print( + ": >>> Out >>> : " + message)
        self.mediator.notify(message, self)

    def receive(self, message):
        print( + ": <<< In <<< : " + message)

class Mediator():
    def __init__(self):
        self.components = []

    def add(self, component):

    def notify(self, message, component):
        for _component in self.components:
            if _component != component:

MEDIATOR = Mediator()
COMPONENT1 = Component(MEDIATOR, "Component1")
COMPONENT2 = Component(MEDIATOR, "Component2")
COMPONENT3 = Component(MEDIATOR, "Component3")