|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
R - Request parameter typepublic interface IHandler<R>
Chain of Responsibility Design Pattern: Avoid coupling the sender of
a request to its receiver by giving 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. (Gamma et al, Design Patterns)
Responsibility: Abstract definition of the "Handler".
//
// Create chain elements
//
IHandler myFirst = new ConcreteHandler();
IHandler mySecond = new ConcreteHandler();
IHandler myThird = new ConcreteHandler();
//
// Associate Handler elements
//
myFirst.setSuccessor(mySecond);
mySecond.setSuccessor(myThird);
//
// Execute the first Handler that triggers the execution of the
// complete chain.
//
myFirst.start(NullRequest.getInstance());
![]() |
![]() |
| Method Summary | |
|---|---|
boolean |
canHandle(R aRequest)
Returns true if this IHandler can handle the given request,
false otherwise. |
IHandler<R> |
getSuccessor()
Returns the Successor handler. |
void |
handle(R aRequest)
Handle the given request. |
void |
setChainStrategy(IChainStrategy aStrategy)
Set the IChainStrategy to this IHandler. |
void |
setSuccessor(IHandler<R> aSuccessor)
Sets the Successor element. |
void |
start(R aRequest)
Triggers execution of the Chain if the target Handler is the first reference, otherwise implements the decision-making regarding forwarding the request to its successor IHandler instance. |
| Method Detail |
|---|
boolean canHandle(R aRequest)
throws IllegalArgumentException
IHandler can handle the given request,
false otherwise.
aRequest - Context-specific request to handle.
IHandler can handle the given request,
false otherwise.
IllegalArgumentException - 'aRequest' must not be null.
void start(R aRequest)
throws IllegalArgumentException
IHandler instance.
aRequest - Context-specific request to handle.
IllegalArgumentException - 'aRequest' must not be null.
void handle(R aRequest)
throws IllegalArgumentException
aRequest - Context-specific request to handle.
IllegalArgumentException - 'aRequest' must not be null.
IllegalArgumentException - 'aRequest' can not be handled.IHandler<R> getSuccessor()
void setSuccessor(IHandler<R> aSuccessor)
throws IllegalArgumentException
aSuccessor - Successor handler
IllegalArgumentException - 'aSuccessor' must not be null.
void setChainStrategy(IChainStrategy aStrategy)
throws IllegalArgumentException
IChainStrategy to this IHandler.
IChainStrategy allows to easily modify how the
Chain should behave. Possible implementations are e.g.
aStrategy - Continuation strategy defines how the chain should
behave
IllegalArgumentException - 'aStrategy' must not be null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||