1 <body> 2 This package contains interfaces and classes for processing class files from 3 the <code>{@link proguard.classfile proguard.classfile}</code> package using 4 the <i>visitor pattern</i>. Cfr., for instance, "Design Patterns, Elements of 5 Reusable OO Software", by Gamma, Helm, Johnson, and Vlissider. 6 <p> 7 Why the visitor pattern? Class files frequently contain lists of elements of 8 various mixed types: class items, constant pool entries, attributes,... 9 These lists and types are largely fixed; they won't change much in future 10 releases of the Java class file specifications. On the other hand, the kinds 11 of operations that we may wish to perform on the class files may change and 12 expand. We want to separate the objects and the operations performed upon them. 13 This is a good place to use the visitor pattern. 14 <p> 15 Visitor interfaces avoid having to do series of <code>instanceof</code> tests 16 on the elements of a list, followed by type casts and the proper operations. 17 Every list element is a visitor accepter. When its <code>accept</code> method 18 is called by a visitor, it calls its corresponding <code>visitX</code> method 19 in the visitor, passing itself as an argument. This technique is called 20 double-dispatch. 21 <p> 22 As already mentioned, the main advantage is avoiding lots of 23 <code>instanceof</code> tests and type casts. Also, implementing a visitor 24 interface ensures you're handling all possible visitor accepter types. Each 25 type has its own method, which you simply have to implement. 26 <p> 27 A disadvantage is that the visitor methods always get the same names, specified 28 by the visitor interface. These names aren't descriptive at all, making code 29 harder to read. It's the visitor classes that describe the operations now. 30 <p> 31 Also, the visitor methods always have the same parameters and return values, as 32 specified by the visitor interfaces. Passing additional parameters is done by 33 means of extra fields in the visitor, which is somewhat of a kludge. 34 <p> 35 Because objects (the visitor accepters) and the operations performed upon them 36 (the visitors) are now separated, it becomes harder to associate some state 37 with the objects. For convenience, we always provide an extra <i>visitor 38 info</i> field in visitor accepters, in which visitors can put any temporary 39 information they want. 40 </body> 41