Nahradí priame väzby medzi objektmi jedným prostredníkom.
class DialogMediator { constructor(toggle, field, button) { this.toggle = toggle; this.field = field; this.button = button; } // The dialog rules live here, in one place. changed(who) { if (who === this.toggle) { this.field.unlock(this.toggle.on); this.button.enable(this.toggle.on); } }} class Toggle { constructor(mediator) { this.mediator = mediator; this.on = false; } flip() { this.on = !this.on; this.mediator.changed(this); }} // A widget knows the mediator and nobody else.const dialog = new DialogMediator(toggle, field, button);toggle.flip();