added chain of responsibility sample
This commit is contained in:
23
chain/src/main/java/com/iluwatar/RequestHandler.java
Normal file
23
chain/src/main/java/com/iluwatar/RequestHandler.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.iluwatar;
|
||||
|
||||
public abstract class RequestHandler {
|
||||
|
||||
private RequestHandler next;
|
||||
|
||||
public RequestHandler(RequestHandler next) {
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
public void handleRequest(Request req) {
|
||||
if (next != null) {
|
||||
next.handleRequest(req);
|
||||
}
|
||||
}
|
||||
|
||||
protected void printHandling(Request req) {
|
||||
System.out.println(this + " handling request \"" + req + "\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String toString();
|
||||
}
|
Reference in New Issue
Block a user