Mediator

The Mediator pattern is like a more civilized version of the Pub Sub pattern. The Pub Sub pattern is just a bunch of modules yelling at each other: “I’M A TAB AND I HAVE BEEN SELECTED, IF ANYBODY CARES!” The trouble with all this yelling becomes apparent when there are conflicts. If two tabs publish the tabSelected event at the same time, which tab actually gets selected? If one tab publishes the tabSelected while another tab is in a frozen state (tabs can be frozen when an alert or prompt window is open), do the tabs switch anyway? Should they? When modules can communicate only through events, these types of conflicts can result in some strange behavior. If you try to fix this behavior while still using only events, your modules might ...

Get Learning to Program now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.