// would like to say: // Shape { // traversal-pp Integer gp1x(){ // bypassing {-> *,p2,*, -> *,y,*} to Integer; // (@ return this; @) } } // will check that path is unique // it is ok to traverse to terminal class // // will create traversal function, create visitor class and object, // and call function // // Instead of // bypassing {-> *,p2,*, -> *,y,*} to Integer;} // would like to say // ordered-through {-> *,p1,*, -> *,x,*} to Integer;} DrawingVisitor { // BAD STYLE before Shape (@ System.out.println("drawing object of " + host.getClass().toString()); @) before ScrollDecorator (@ System.out.println(" draw scroll bar "); @) before BorderDecorator (@ System.out.println(" draw border "); @) before Line (@ // Cursor.move(host.get_p1x(), host.get_p1y()); Cursor.move(host.get_coords().get_p1().get_x(), host.get_coords().get_p1().get_y()); Cursor.line(host.get_coords().get_p2().get_x(),host.get_coords().get_p2().get_y()); @) before Box (@ Cursor.move(host.get_coords().get_p1().get_x(), host.get_coords().get_p1().get_y()); Cursor.line(host.get_coords().get_p1().get_x(),host.get_coords().get_p2().get_y()); Cursor.line(host.get_coords().get_p2().get_x(),host.get_coords().get_p2().get_y()); Cursor.line(host.get_coords().get_p2().get_x(),host.get_coords().get_p1().get_y()); Cursor.line(host.get_coords().get_p1().get_x(),host.get_coords().get_p1().get_y()); @) } Sketch { traversal allShapes(DrawingVisitor d) { bypassing -> *,mode,* to {Box, Line};} // go to subclasses of Shape (@ void draw(Color c) { DrawingVisitor d = new DrawingVisitor(c); this.allShapes(d); } @) } Cursor { (@ static void move(Integer x, Integer y) { System.out.println(" move to " + x + " , " + y);} static void line(Integer x, Integer y) { System.out.println(" line to " + x + " , " + y);} @) } Main { (@ public static void main(String args[]) throws Exception { System.out.println(" *** START *** "); Sketch s = Sketch.parse(System.in); s.draw(new Black()); } @) }