4 package net.sf.openrocket.rocketcomponent;
7 * This interface describes a portion of the Visitor pattern, using generics to assure type-safety.
8 * The elements of the concrete object hierarchy are only visitable by an associated hierarchy of visitors,
9 * while these visitors are only able to visit the elements of that hierarchy.
11 * The key concept regarding the Visitor pattern is to realize that Java will only ÒdiscriminateÓ the type of an
12 * object being called, not the type of an object being passed.
14 * In order for the type of two objects to be determinable to the JVM, each object must be the receiver of an
15 * invocation. Here, when accept is called on a Visitable, the concrete type of the Visitable becomes ÒknownÓ but the
16 * concrete type of the argument is still unknown. <code>visit</code> is then called on the parameter object, passing
17 * the Visitable back, which has type and identity. Flow of control has now been 'double-dispatched' such that the
18 * type (and identity) of both objects are known.
20 * Specifically, this interface is to be implemented by every class in the RocketComponent hierarchy that
21 * can be visited AND which are sufficiently specialized from their super class. If they only provide
22 * constraints to their superclass (such as TubeCoupler), then the implementation of this interface at
23 * the superclass level is sufficient.
25 * Admittedly, the syntax is a bit contorted here, as it is necessarily self-referential for type-safety.
27 * <V> The visitor type (the concrete class that implements this interface)
30 public interface Visitor<V extends Visitor<V, T>, T extends Visitable<V, T>> {
33 * The callback method. This method is the 2nd leg of the double-dispatch, having been invoked from a
34 * corresponding <code>accept</code>.
36 * @param visitable the instance of the Visitable (the target of what is being visiting)
38 void visit(T visitable);