Bruce Eckel ede3954d86 March 2021 Book Update
See notes in "Foreword to the Leanpub Edition"
2021-03-04 16:15:04 -07:00

32 lines
979 B
Java

// 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);
}