forked from hazukac/DesignPatterns
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSupport.java
More file actions
31 lines (30 loc) · 946 Bytes
/
Copy pathSupport.java
File metadata and controls
31 lines (30 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public abstract class Support {
private String name;
private Support next;
public Support(String name) {
this.name = name;
}
public Support setNext(Support nextSupport) {
this.next = nextSupport;
return this.next;
}
public final void support(Trouble trouble) {
if (this.resolve(trouble)) {
done(trouble);
} else if (this.next != null) {
this.next.support(trouble);
} else {
this.fail(trouble);
}
}
public String toString() {
return "[" + this.name + "]";
}
protected abstract boolean resolve(Trouble trouble);
protected void done(Trouble trouble) {
System.out.println(trouble.toString() + " is resolved by " + this.toString() + ".");
}
protected void fail(Trouble trouble) {
System.out.println(trouble.toString() + "cannot be resolved by " + this.toString() + ".");
}
}