Early previewThis guide is in development. Items tagged verify are still being checked against official docs.
nebx Learn
GitHub
Menu
Go

Go

Simple, fast to compile, built for concurrent network services.

Paradigm
Procedural, composition over inheritance
Typing
Static, strong, structural interfaces
Memory
Concurrent low-latency GC
Runs
Single static native binary
Concurrency
Goroutines and channels
Behavioral pattern

Mediator

Intent

Reduces chaotic dependencies between objects by making them communicate through a mediator object.

Problem

Form fields reference each other directly; changing one breaks five others.

Solution

Components notify a mediator, which decides who reacts.

Real-world analogy

Think of it like this

Air traffic control: pilots talk to the tower, not to each other.

Structure

association / extends implements / depends on
«interface» Mediator + notify(sender) 2 ConcreteMediator - componentA- componentB+ notify(sender) 3 ComponentA - m: Mediator+ operationA() 1 ComponentB - m: Mediator+ operationB() 4

Hover or tap a numbered role to highlight it in the diagram.

  1. 1ComponentA — Components hold business logic and a reference to the mediator, never to each other.
  2. 2Mediator — Mediator declares how components report events.
  3. 3ConcreteMediator — Concrete Mediator encapsulates the relations between components and decides who reacts.
  4. 4ComponentB — Components don't know which other components exist, so each can be reused alone.

Code example

A Go code sample for Mediator is coming soon. Factory Method, Singleton, Decorator, Observer and Strategy already have code in all six languages.

Applicability

Use Mediator when classes are tightly coupled through many references.

Use Mediator when components can't be reused because they depend on too many others.

Pros and cons

Pros

  • Reduced coupling
  • Reusable components

Cons

  • The mediator can grow into a god object

Check yourself

Check yourself

Dialog widgets (checkbox, text field, button) must enable and disable each other without direct references.

Saved in this browser only. Part of Behavioral patterns (0/11).