2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								layout: pattern
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								title: Mediator
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								folder: mediator
							 
						 
					
						
							
								
									
										
										
										
											2015-08-15 18:03:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								permalink: /patterns/mediator/
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 21:40:07 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								categories: Behavioral
							 
						 
					
						
							
								
									
										
										
										
											2015-09-22 18:25:56 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								tags:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 -  Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 -  Gang Of Four
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 -  Difficulty-Intermediate
							 
						 
					
						
							
								
									
										
										
										
											2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-03 21:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Intent
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Define an object that encapsulates how a set of objects interact.
							 
						 
					
						
							
								
									
										
										
										
											2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								Mediator promotes loose coupling by keeping objects from referring to each
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								other explicitly, and it lets you vary their interaction independently.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-03 21:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Applicability
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Use the Mediator pattern when
							 
						 
					
						
							
								
									
										
										
										
											2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  a set of objects communicate in well-defined but complex ways. The resulting interdependencies are unstructured and difficult to understand
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  reusing an object is difficult because it refers to and communicates with many other objects
							 
						 
					
						
							
								
									
										
										
										
											2015-08-15 18:03:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  a behavior that's distributed between several classes should be customizable without a lot of subclassing
							 
						 
					
						
							
								
									
										
										
										
											2015-09-22 18:25:56 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-20 20:57:48 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Real world examples
 
							 
						 
					
						
							
								
									
										
										
										
											2016-08-20 20:49:28 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  All scheduleXXX() methods of [java.util.Timer ](http://docs.oracle.com/javase/8/docs/api/java/util/Timer.html )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  [java.util.concurrent.Executor#execute() ](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Executor.html#execute-java.lang.Runnable- )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  submit() and invokeXXX() methods of [java.util.concurrent.ExecutorService ](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  scheduleXXX() methods of [java.util.concurrent.ScheduledExecutorService ](http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ScheduledExecutorService.html )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  [java.lang.reflect.Method#invoke() ](http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Method.html#invoke-java.lang.Object-java.lang.Object...- )
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-03 21:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Credits
 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-22 18:25:56 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-08-20 20:49:28 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  [Design Patterns: Elements of Reusable Object-Oriented Software ](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612 )