Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

@Pattern(name="Chain of Responsibility", scope=Object, purpose=Behavioural, participants={"Handler","ConcreteHandler","Client"})

Package dk.rode.thesis.chainofresponsibility

Implementations and examples of the Chain of Responsibility design pattern [Gamma95, p.223].

See:
          Description

Interface Summary
Handler<R> A handler can handle a given type of request by taking appropriate action or by forwarding the request to the next handler in the current chain of handlers.
HandlerChain<R> A handler chain is an ordered list of handlers that will be passed a request in turn until the first applicable handler can handle it.
HandlerLink<R> A handler link represents a connection to the next handler in a given handler chain.
 

Class Summary
AbstractHandlerChain<R> An abstract handler chain implements the basic traits of the HandlerChain interface.
CharacterHandler An abstract character handler implements the basic traits of handlers handling Character objects.
LetterCaseHandler A letter case handler is a handler that can handle letter characters in either upper or lower case only.
LetterHandler A letter handler is a handler that can handle letter characters.
Main Chain of Responsibility tests.
StandardHandlerChain<R> A standard handler chain is the standard implementation of the HandlerChain interface.
SymbolHandler A symbol handler is a handler that can handle symbol characters.
WeakHandlerChain<R> A weak handler chain is a thread-safe handler chain storing registered handlers as weak references.
WhitespaceHandler A whitespace handler is a handler that can handle whitespace characters.
 

Package dk.rode.thesis.chainofresponsibility Description

Implementations and examples of the Chain of Responsibility design pattern [Gamma95, p.223].

Intent:

Here, the Handler participant is represented by the Handler interface, and the ConcreteHandler participant by any Handler implementation. Several handler implementations are defined in this package, all sub-classes of the CharacterHandler class, each thus handling Character objects. Examples include SymbolHandler and LetterCaseHandler.

The Client participant is the test application, i.e. the Main class.

UML Class Diagram:

Implementation notes:
This implementation differs from the canonical "Gang of Four" implementation in that it makes the handler chain explicit using the HandlerChain interface. Here, handlers need not store the successor in the chain locally, and can participate in several chains concurrently. The link to the next handler is supplied at execution time using a HandlerLink.

Two explicit HandlerChain implementations have been made, namely StandardHandlerChain and WeakHandlerChain. The first is a simple implementation that is not thread-safe, while the latter is thread-safe and stores handlers as weak references.

Author:
Gunni Rode / rode.dk

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.