2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								layout: pattern
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								title: Chain of responsibility
							 
						 
					
						
							
								
									
										
										
										
											2015-08-31 23:13:35 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								folder: chain
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								permalink: /patterns/chain/
							 
						 
					
						
							
								
									
										
										
										
											2016-08-30 15:10:34 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								pumlid: 9SR13SCm20NGLTe1OkxTXX0KKzd4Wa-pVYlrdTxJN4OTMZ4U7LZv8Wg-ssdejLTgoELGHvDhaesw6HpqvWzlXwQTlYq6D3nfSlv2qjcS5F9VgvXjrHnV
							 
						 
					
						
							
								
									
										
										
										
											2015-08-20 21:40:07 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								categories: Behavioral
							 
						 
					
						
							
								
									
										
										
										
											2015-09-22 18:25:56 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								tags:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 -  Java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 -  Gang Of Four
							 
						 
					
						
							
								
									
										
										
										
											2015-12-28 15:52:44 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 -  Difficulty-Intermediate
							 
						 
					
						
							
								
									
										
										
										
											2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-03 21:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Intent
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Avoid coupling the sender of a request to its receiver by giving
							 
						 
					
						
							
								
									
										
										
										
											2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								more than one object a chance to handle the request. Chain the receiving
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								objects and pass the request along the chain until an object handles it.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-31 23:18:55 +03:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-03 21:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Applicability
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Use Chain of Responsibility when
							 
						 
					
						
							
								
									
										
										
										
											2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  more than one object may handle a request, and the handler isn't known a priori. The handler should be ascertained automatically
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  you want to issue a request to one of several objects without specifying the receiver explicitly
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  the set of objects that can handle a request should be specified dynamically
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-03 21:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Real world examples
 
							 
						 
					
						
							
								
									
										
										
										
											2015-08-13 23:54:40 +02:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  [java.util.logging.Logger#log() ](http://docs.oracle.com/javase/8/docs/api/java/util/logging/Logger.html#log%28java.util.logging.Level,%20java.lang.String%29 )
							 
						 
					
						
							
								
									
										
										
										
											2015-08-15 18:03:05 +02:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  [Apache Commons Chain ](https://commons.apache.org/proper/commons-chain/index.html )
							 
						 
					
						
							
								
									
										
										
										
											2016-08-20 20:49:28 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*  [javax.servlet.Filter#doFilter() ](http://docs.oracle.com/javaee/7/api/javax/servlet/Filter.html#doFilter-javax.servlet.ServletRequest-javax.servlet.ServletResponse-javax.servlet.FilterChain- )
							 
						 
					
						
							
								
									
										
										
										
											2015-09-22 18:25:56 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-01-03 21:14:30 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								## Credits
 
							 
						 
					
						
							
								
									
										
										
										
											2015-09-22 18:25:56 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*  [Design Patterns: Elements of Reusable Object-Oriented Software ](http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612 )