/chain-of-responsability

Simple project demonstrating the Chain of Responsability design pattern. I've made a representation of a postal system.

Primary LanguageJavaGNU General Public License v3.0GPL-3.0

Chain of Responsability

Code

Simple project representing the Chain of Responsability design pattern. I've made a representation of a postal system.

Definition

Chain of Responsibility is a behavioral design pattern that lets you pass requests along a chain of handlers. Upon receiving a request, each handler decides either to process the request or to pass it to the next handler in the chain.

image

The chain-of-responsibility pattern is structurally nearly identical to the decorator pattern, the difference being that for the decorator, all classes handle the request, while for the chain of responsibility, exactly one of the classes in the chain handles the request. This is a strict definition of the Responsibility concept in the GoF book. However, many implementations (such as loggers below, or UI event handling, or servlet filters in Java, etc) allow several elements in the chain to take responsibility.

Real-World Analogy

image

Source: Wikipedia | Refactoring Guru