Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. Create visitor class
- public interface Visitor
- {
- public void visit(Body b);
- }
- public class DooVisitor implements Visitor
- {
- //2. Make instance of visitor in new class
- public static DooVisitor dv = new DooVisitor();
- //4. Move Methods leaving delegate behind
- //5. Rename methods in visitor class to visit
- public void visit(Body b) {
- System.out.println("Body does " + b.role);
- }
- }
- public interface CarElement
- {
- public void accept(DooVisitor v);
- }
- //3. Add visitor-type parameter to OG classes
- public class Body implements CarElement
- {
- public String role = "protect passengers";
- //4. Move Methods leaving behind delegate method
- //5. Rename methods in OG class to accept
- public void accept(DooVisitor v) {
- v.visit(this);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement