forked from BruceEckel/OnJava8-Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisitor.java
More file actions
31 lines (30 loc) · 979 Bytes
/
Visitor.java
File metadata and controls
31 lines (30 loc) · 979 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
// patterns/trash/Visitor.java
// (c)2021 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
// The base class for Visitors.
package patterns.trash;
public abstract class Visitor {
protected double alTotal; // Aluminum
protected double pTotal; // Paper
protected double gTotal; // Glass
protected double cTotal; // Cardboard
protected String descriptor;
protected Visitor(String descriptor) {
this.descriptor = descriptor;
}
protected void show(String type, double value) {
System.out.printf(
"%s %s: %.2f%n", type, descriptor, value);
}
public void total() {
show("Total Aluminum", alTotal);
show("Total Paper", pTotal);
show("Total Glass", gTotal);
show("Total Cardboard", cTotal);
}
abstract void visit(Aluminum a);
abstract void visit(Paper p);
abstract void visit(Glass g);
abstract void visit(Cardboard c);
}