The Visitor and Visitable Objects
The Visitor Design Pattern uses to interfaces to form its structure: Visitor and Visitable.
A visitor object implements a Visitor interface which at minimum has a visit() method.
The Order and Item objects - which implement a Visitable interface - both have an accept() method.
A Visitable object accepts a Visitor (i.e. this.accept(Visitor visitor)), and a Visitor visits a Visitable object (i.e. visitor.visit(this)).
These interfaces are very simple and are shown below.
// ************************************************************************
/*
* Visitor.java
*
* Provides a simple Visitor interface for the Visitor Design Pattern Example.
*/
// ************************************************************************
interface Visitor {
public void visit(Object o);
} //endinterface: Visitor.java
// ************************************************************************
/*
* Visitable.java
*
* Provides a simple Visitable interface for the Visitor Design Pattern Example.
*/
// ************************************************************************
interface Visitable {
public void accept(Visitor visitor);
} //endinterface: Visitable