Skip to content

Latest commit

 

History

History

mediator

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Table of Contents generated with DocToc

Mediator pattern

"is a design pattern that allows us to expose a unified interface through which the different parts of a system may communicate" - Essential JS design patterns, Addy Osmani

It's also normally defined as a behavioral pattern.

img1

Source

img2

Source

Example:

const orgChart = {
  addEmployee: function(){
    const details = this.getDetails();
    details.on('ev1', function(){
      const manager = this.getManager(employee);
      manager.on('ev2', function(){
        employee.save();
      });
    });
  }
}

Pros

  • Reduces the interaction between different parties from many to one
  • Helps in the process of decoupling objects which often promotes smaller, reusable components.

Cons

  • Introduces a single point of failure

Resources