|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
R
- The request type handled by this handler.@Participant(value="Handler") public interface 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.
A handler is only linked
to the next handler
at execution time, and hence a handler can participate in several
handler chains, which the original "Gang of Four" solution could
not.
The actual code required to support the handler chain semantics is minimal in handler implementations:
public Handler<R>handle
(R request,HandlerLink
<R> link) { // Unique for each handler implementation... if (.. request can be handled ..) { .. return this; } // Identical for *every* handler implementation... return link == null ? null : link.handle
(request, this); }
Method Summary | |
---|---|
Handler<R> |
handle(R request,
HandlerLink<R> link)
Handles the request supplied as request or
forwards it to the next handler in the chain represented
by the handler link supplied as
link , if any. |
Method Detail |
---|
Handler<R> handle(R request, HandlerLink<R> link)
request
or
forwards it to the next handler in the chain represented
by the handler link
supplied as
link
, if any. link
can be null,
in which case this handler is considered the last
handler in the chain.
If this handler handles request
, this handler
is returned. If this handler cannot handle request
,
the result from handling the request using link
is returned. Finally, if link
is null, null is
returned.
request
- The request to handle; nullability determined
by the actual handler implementation.link
- The link to the next handler in the current
chain; can be null.
request
, if any.
Can be null.
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |